locked
CryptEncrypt fails to return length of buffer on Windows 7 64 bit box when running a dll targetted for 32 bit. RRS feed

  • General discussion

  • I am creating a derive key from user supplied password. 

    CryptCreateHash -> CALG_MD5

    CryptDeriveKey -> CALG_RC4

     

    CryptEncrypt function returns dwEncryptedBufferLen = 0 

    See function call below - 

     

    CryptEncrypt( mhCryptKey, 

    NULL, 

    TRUE,

    dwFlags, 

    NULL, 

    &dwEncryptedBufferLen, 

    0)

     

    Any clues what could be wrong in this?

    Friday, June 11, 2010 1:51 PM

All replies

  • Hi,

    What is the value of dwEncryptedBufferLen on input?
    I suspect that may be it is set to 0 on input and that's why you obtain 0 on output...

    Cheers,
    --
    Mounir IDRASSI
    IDRIX
    http://www.idrix.fr

    Sunday, June 13, 2010 2:00 AM
  • Yes it is 0 but CryptEncrypt should give me buffer size in case I pass parameter as NULL.  Thats the way i will get the length of buffer i need to store the encrypted text.

     

    Thanks,

    Sachin

    Monday, June 14, 2010 4:57 PM
  • Hi,

    Actually, you are mistaken in your understanding of how CryptEncrypt works. If you read the MSDN documentation of the sixth parameter (that is &dwEncryptedBufferLen in your sample), you'll find the following :

    • A pointer to a DWORD value that , on entry, contains the length, in bytes, of the plaintext in the pbData buffer. On exit, this DWORD contains the length, in bytes, of the ciphertext written to the pbData buffer.

    So, in input, dwEncryptedBufferLen must contain the length of the plain data and on output you'ill get the necessary size to store the encrypted data.

    By setting dwEncryptedBufferLento 0 on input, you are basically telling CryptEncrypt that you want to encrypt zero bytes: so, as expected, you are getting zeros bytes in output!

    I hope this clarifies things to you.
    Cheers,
    --
    Mounir IDRASSI
    IDRIX
    http://www.idrix.fr

    Monday, June 14, 2010 11:36 PM
  • You are right. Actually I completely missed this. Thanks.

    Sachin

    Tuesday, June 15, 2010 12:37 AM