C++ help for Encryption to generate CVC

View: New views
1 Messages — Rating Filter:   Alert me  

C++ help for Encryption to generate CVC

by CipherAnil :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I am trying to generate a Dynamic CVC(Card Verification Code) number for a digital Card using 3DES algorithm. To generate the CVC i need to use a standard key and encrypt a data like
[0D 14 00 00 08 99 00 5E]  sample data(8 byte).

Can anybody post a sample code on how to encrypt it as ASAP.

Post my sample code.
::Encrypt(CString Key, CString Data, CString *Cryptogram)
{
        int rc,len,copied=0;
        int nTemp = -1;
        nTemp = cryptInit();
        char unsigned Buffer[1000];
        memset(Buffer,0x00,1000);
        memcpy(Buffer,(LPCTSTR)Data,Data.GetLength());
        len = (int)strlen((char *)Buffer);
        CRYPT_ENVELOPE cryptEnvelope;
        rc=cryptCreateEnvelope( &cryptEnvelope, CRYPT_UNUSED, CRYPT_FORMAT_CRYPTLIB );
        rc=cryptSetAttribute( cryptEnvelope, CRYPT_OPTION_ENCR_ALGO,CRYPT_ALGO_3DES);
        cryptSetAttribute( cryptEnvelope, CRYPT_ATTRIBUTE_BUFFERSIZE, 90000L );
        cryptSetAttributeString( cryptEnvelope, CRYPT_ENVINFO_PASSWORD, Key.LockBuffer(), Key.GetLength());
        rc=cryptSetAttribute( cryptEnvelope, CRYPT_ENVINFO_DATASIZE, Data.GetLength());
        rc=cryptPushData( cryptEnvelope, Buffer, len, &copied );
        rc=cryptFlushData( cryptEnvelope);
        memset(Buffer,0x00,1000);
        cryptPopData( cryptEnvelope, Buffer, 1000, &copied);
        *Cryptogram=ByteToHexString(&Buffer[0],copied);
        cryptDestroyEnvelope( cryptEnvelope );
        Key.ReleaseBuffer();

Anil