Michael Prendergast
2004-10-28 19:29:01 UTC
Hello,
I have a strange little bug that keeps occurring whenever I make a call to
CryptEncrypt():
It seems that whenever I call CryptEncrypt() to encrypt a plaintext buffer
of greater than 53 bytes, it fails and returns NTE_BAD_LEN through
GetLastError(). This seems independent of the actual buffer size I pass in.
For example, I tried getting the size required to encrypt a 58 byte buffer,
and gave CryptEncrypt() a size of 1000 for the actual buffer length, and
received NTE_BAD_LEN in response.
Here's some sample code:
---------------------------------------------------------------------
ULONG ulEncryptedDataSizeInBytes = 58;
if (CryptEncrypt(m_hRemotePublicKey, 0, TRUE, 0, NULL,
&ulEncryptedDataSizeInBytes, 1000) == FALSE)
{
hrReturnValue = GetLastError();
}
}
---------------------------------------------------------------------
I'm using MS_DEF_PROV as the cryptographic provider name, with PROV_RSA_FULL
and CALG_RSA_KEYX as the encryption algorithm (I'm using this encryption for
a public key exchange sequence).
Does anyone have any idea what could be wrong? Is there something I need to
set with SetKeyParam() first?
Also, as a side note, this works if I make repeated calls to CryptEncrypt()
with temporary copy buffers of less 32 bytes each.
Any help would be greatly appreciated.
Thank you very much for your help.
Ciao,
Michael Prendergast
I have a strange little bug that keeps occurring whenever I make a call to
CryptEncrypt():
It seems that whenever I call CryptEncrypt() to encrypt a plaintext buffer
of greater than 53 bytes, it fails and returns NTE_BAD_LEN through
GetLastError(). This seems independent of the actual buffer size I pass in.
For example, I tried getting the size required to encrypt a 58 byte buffer,
and gave CryptEncrypt() a size of 1000 for the actual buffer length, and
received NTE_BAD_LEN in response.
Here's some sample code:
---------------------------------------------------------------------
ULONG ulEncryptedDataSizeInBytes = 58;
if (CryptEncrypt(m_hRemotePublicKey, 0, TRUE, 0, NULL,
&ulEncryptedDataSizeInBytes, 1000) == FALSE)
{
hrReturnValue = GetLastError();
}
}
---------------------------------------------------------------------
I'm using MS_DEF_PROV as the cryptographic provider name, with PROV_RSA_FULL
and CALG_RSA_KEYX as the encryption algorithm (I'm using this encryption for
a public key exchange sequence).
Does anyone have any idea what could be wrong? Is there something I need to
set with SetKeyParam() first?
Also, as a side note, this works if I make repeated calls to CryptEncrypt()
with temporary copy buffers of less 32 bytes each.
Any help would be greatly appreciated.
Thank you very much for your help.
Ciao,
Michael Prendergast