decryption code throwing a hissyfit.

H

hazz

Here is a method that throws a NullReferenceException at the line pointed to
below . szCharKey is undefined at that point.
Before FromDoubleByte() is called , szCharkey has a value of "1234"

The call stack shows FromDoubleByte(char* pszIn = 0x001bfb18, unsigned char*
pbOut = 0x0012eb10, __int32 nBufLen = 880) Line 228 C++

Any ideas where I should look? values for szStringToDecrypt and pszIn are
given at bottom. Thank you. -greg
----------------------------------------------------------------------------
------------------------------------

String* DeCryptString(String &szStringToDecrypt, String &szCharKey)
{
HCRYPTPROV hProv = NULL;
HCRYPTKEY hKey = NULL;
HCRYPTHASH hHash = NULL;
PBYTE pbBuffer = NULL;
int nCount = 0;
String* sDecryptedString;
BYTE ucCondensed[MAX_PATH];

int nBufLen = szStringToDecrypt.Length;
char* pszDoubleWideString =
(char*)(void*)Marshal::StringToHGlobalAnsi(&szStringToDecrypt);
FromDoubleByte( pszDoubleWideString, ucCondensed, nBufLen );
nBufLen /= 2;

String* sKey;
if(szCharKey.Length > 0) <----------------//NullReferenceExeption thrown
here
..........
}


void FromDoubleByte(char* pszIn, PBYTE pbOut, int nBufLen)
-----------------
{
int i;
int j;
int nOneChar;
int nByteValue;

for( i=0, j=0; i< (long)nBufLen; )
{
// Read first of two bytes
nOneChar = pszIn[i++];
if( nOneChar < 58 )
{
nByteValue = (( nOneChar - '0' ) * 16);
}
else
{
nByteValue = (( nOneChar - ( 'A' - 10 ) ) * 16);
}

// Read second of two bytes
nOneChar = pszIn[i++];
if( nOneChar < 58 )
{
nByteValue += ( nOneChar - '0' );
}
else
{
nByteValue += ( nOneChar - ( 'A' - 10 ) );
}

//Put in buffer
pbOut[j++] = (unsigned char)nByteValue;
}
}




szStringToDecrypt =
"5E45D91532071793F87E543E6DF59A6A792F9790918F6D2F1D80D3D9D34B9DA92DB536343C7
D71A371F68485271A9B6AD57CDD654770C015852A78E573551FDFD0B40529DB28CD6A55F3098
02488212CEB9A15C5C1CC464826D05762D83B0989AA8AD26F5748A93FC853820319423ABE788
8571058CCEC9D46DC22F8F42BA7550ADE3E857D5F86FBD3E3415B885E9489058D635FBF2DD49
96EA62302F6A84AC997C42936CA3A2BFB631D10D7542E6B267D302A1F93D40F4926CB929FE81
FD66AAB96D7F0F1B51ACCC5C74C0C4B0AAE240C3CD0A2AEBA45F44D02771D584353969E9CBD3
F00E99F5CF7797B06F7D4350EABA81A4CEDCD288FE38445817237936621E367791EE49CC09DB
C6227600CF361923B2BDF81E96496B103A17B6884C985E48559B4DA50B266B4438A5E2A8762E
70A0CFED667F0677E717CF14014C9D4429F694D2A0654B6E13A612B7B40EF3E122B01992640C
3C6484B493A293BA4FB9AEFCA94F3BD2365FAAF917358F3AA67FE9FD15B978FDF772E3EC3A77
246A3D70996449DCBC145FE83FBA54F653EB5E60D624D48508505AAB612AEC0E115F5F47D7A5
CDE68F22662F1D693A133337B2C512957D2C4F0DA84D9"

pszIn = 0x001bfb70
"8D1E82F58E8953AD3ED791461570E2D57E8DB057CEB5BC4E174B466354E04FE3D091A03F1E4
7612BCC7CB4409AF6BB44B06277F4D065ABD70B204B23CE94010D1DEB5B443664BCDF3B7BE04
59C45DCD80B03B232040A5267225882E510CB45966F1EDD9B0323EAC7BC8FD36993B34899210
2303570420323A967DB1517D8F99H" char*
 
H

hazz

if szStringToDecrypt is shorter than the offending input string to encrypt,
as when "test" is the encrypted string, no problem.

hazz said:
Here is a method that throws a NullReferenceException at the line pointed to
below . szCharKey is undefined at that point.
Before FromDoubleByte() is called , szCharkey has a value of "1234"

The call stack shows FromDoubleByte(char* pszIn = 0x001bfb18, unsigned char*
pbOut = 0x0012eb10, __int32 nBufLen = 880) Line 228 C++

Any ideas where I should look? values for szStringToDecrypt and pszIn are
given at bottom. Thank you. -greg
-------------------------------------------------------------------------- --
------------------------------------

String* DeCryptString(String &szStringToDecrypt, String &szCharKey)
{
HCRYPTPROV hProv = NULL;
HCRYPTKEY hKey = NULL;
HCRYPTHASH hHash = NULL;
PBYTE pbBuffer = NULL;
int nCount = 0;
String* sDecryptedString;
BYTE ucCondensed[MAX_PATH];

int nBufLen = szStringToDecrypt.Length;
char* pszDoubleWideString =
(char*)(void*)Marshal::StringToHGlobalAnsi(&szStringToDecrypt);
FromDoubleByte( pszDoubleWideString, ucCondensed, nBufLen );
nBufLen /= 2;

String* sKey;
if(szCharKey.Length > 0) <----------------//NullReferenceExeption thrown
here
.........
}


void FromDoubleByte(char* pszIn, PBYTE pbOut, int nBufLen)
-----------------
{
int i;
int j;
int nOneChar;
int nByteValue;

for( i=0, j=0; i< (long)nBufLen; )
{
// Read first of two bytes
nOneChar = pszIn[i++];
if( nOneChar < 58 )
{
nByteValue = (( nOneChar - '0' ) * 16);
}
else
{
nByteValue = (( nOneChar - ( 'A' - 10 ) ) * 16);
}

// Read second of two bytes
nOneChar = pszIn[i++];
if( nOneChar < 58 )
{
nByteValue += ( nOneChar - '0' );
}
else
{
nByteValue += ( nOneChar - ( 'A' - 10 ) );
}

//Put in buffer
pbOut[j++] = (unsigned char)nByteValue;
}
}




szStringToDecrypt =
"5E45D91532071793F87E543E6DF59A6A792F9790918F6D2F1D80D3D9D34B9DA92DB536343C7D71A371F68485271A9B6AD57CDD654770C015852A78E573551FDFD0B40529DB28CD6A55F309802488212CEB9A15C5C1CC464826D05762D83B0989AA8AD26F5748A93FC853820319423ABE7888571058CCEC9D46DC22F8F42BA7550ADE3E857D5F86FBD3E3415B885E9489058D635FBF2DD4996EA62302F6A84AC997C42936CA3A2BFB631D10D7542E6B267D302A1F93D40F4926CB929FE81FD66AAB96D7F0F1B51ACCC5C74C0C4B0AAE240C3CD0A2AEBA45F44D02771D584353969E9CBD3F00E99F5CF7797B06F7D4350EABA81A4CEDCD288FE38445817237936621E367791EE49CC09DBC6227600CF361923B2BDF81E96496B103A17B6884C985E48559B4DA50B266B4438A5E2A8762E70A0CFED667F0677E717CF14014C9D4429F694D2A0654B6E13A612B7B40EF3E122B01992640C3C6484B493A293BA4FB9AEFCA94F3BD2365FAAF917358F3AA67FE9FD15B978FDF772E3EC3A77246A3D70996449DCBC145FE83FBA54F653EB5E60D624D48508505AAB612AEC0E115F5F47D7A5
CDE68F22662F1D693A133337B2C512957D2C4F0DA84D9"

pszIn = 0x001bfb70
"8D1E82F58E8953AD3ED791461570E2D57E8DB057CEB5BC4E174B466354E04FE3D091A03F1E47612BCC7CB4409AF6BB44B06277F4D065ABD70B204B23CE94010D1DEB5B443664BCDF3B7BE0459C45DCD80B03B232040A5267225882E510CB45966F1EDD9B0323EAC7BC8FD36993B34899210
2303570420323A967DB1517D8F99H" char*
 
Top