473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

decryption code throwing a hissyfit.

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(&szStri ngToDecrypt);
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 =
"5E45D91532071793F87E543E6DF59A6A792F9790918F6D2F1 D80D3D9D34B9DA92DB536343C7
D71A371F68485271A9B6AD57CDD654770C015852A78E573551 FDFD0B40529DB28CD6A55F3098
02488212CEB9A15C5C1CC464826D05762D83B0989AA8AD26F5 748A93FC853820319423ABE788
8571058CCEC9D46DC22F8F42BA7550ADE3E857D5F86FBD3E34 15B885E9489058D635FBF2DD49
96EA62302F6A84AC997C42936CA3A2BFB631D10D7542E6B267 D302A1F93D40F4926CB929FE81
FD66AAB96D7F0F1B51ACCC5C74C0C4B0AAE240C3CD0A2AEBA4 5F44D02771D584353969E9CBD3
F00E99F5CF7797B06F7D4350EABA81A4CEDCD288FE38445817 237936621E367791EE49CC09DB
C6227600CF361923B2BDF81E96496B103A17B6884C985E4855 9B4DA50B266B4438A5E2A8762E
70A0CFED667F0677E717CF14014C9D4429F694D2A0654B6E13 A612B7B40EF3E122B01992640C
3C6484B493A293BA4FB9AEFCA94F3BD2365FAAF917358F3AA6 7FE9FD15B978FDF772E3EC3A77
246A3D70996449DCBC145FE83FBA54F653EB5E60D624D48508 505AAB612AEC0E115F5F47D7A5
CDE68F22662F1D693A133337B2C512957D2C4F0DA84D9"

pszIn = 0x001bfb70
"8D1E82F58E8953AD3ED791461570E2D57E8DB057CEB5BC4E1 74B466354E04FE3D091A03F1E4
7612BCC7CB4409AF6BB44B06277F4D065ABD70B204B23CE940 10D1DEB5B443664BCDF3B7BE04
59C45DCD80B03B232040A5267225882E510CB45966F1EDD9B0 323EAC7BC8FD36993B34899210
2303570420323A967DB1517D8F99H" char*
Nov 17 '05 #1
1 837
if szStringToDecrypt is shorter than the offending input string to encrypt,
as when "test" is the encrypted string, no problem.

"hazz" <ha**@sonic.net> wrote in message
news:eT**************@tk2msftngp13.phx.gbl...
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(&szStri ngToDecrypt);
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 =
"5E45D91532071793F87E543E6DF59A6A792F9790918F6D2F1 D80D3D9D34B9DA92DB536343C7 D71A371F68485271A9B6AD57CDD654770C015852A78E573551 FDFD0B40529DB28CD6A55F3098 02488212CEB9A15C5C1CC464826D05762D83B0989AA8AD26F5 748A93FC853820319423ABE788 8571058CCEC9D46DC22F8F42BA7550ADE3E857D5F86FBD3E34 15B885E9489058D635FBF2DD49 96EA62302F6A84AC997C42936CA3A2BFB631D10D7542E6B267 D302A1F93D40F4926CB929FE81 FD66AAB96D7F0F1B51ACCC5C74C0C4B0AAE240C3CD0A2AEBA4 5F44D02771D584353969E9CBD3 F00E99F5CF7797B06F7D4350EABA81A4CEDCD288FE38445817 237936621E367791EE49CC09DB C6227600CF361923B2BDF81E96496B103A17B6884C985E4855 9B4DA50B266B4438A5E2A8762E 70A0CFED667F0677E717CF14014C9D4429F694D2A0654B6E13 A612B7B40EF3E122B01992640C 3C6484B493A293BA4FB9AEFCA94F3BD2365FAAF917358F3AA6 7FE9FD15B978FDF772E3EC3A77 246A3D70996449DCBC145FE83FBA54F653EB5E60D624D48508 505AAB612AEC0E115F5F47D7A5 CDE68F22662F1D693A133337B2C512957D2C4F0DA84D9"

pszIn = 0x001bfb70
"8D1E82F58E8953AD3ED791461570E2D57E8DB057CEB5BC4E1 74B466354E04FE3D091A03F1E4 7612BCC7CB4409AF6BB44B06277F4D065ABD70B204B23CE940 10D1DEB5B443664BCDF3B7BE04 59C45DCD80B03B232040A5267225882E510CB45966F1EDD9B0 323EAC7BC8FD36993B34899210 2303570420323A967DB1517D8F99H" char*

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jase H | last post by:
Hello, I have a ASP.NET web application problem involving the data encryption and decryption assembly(DLL) used on the connection string value that is set in the webconfig file. The problem...
1
by: Jase H | last post by:
Hello, I have a ASP.NET web application problem involving the data encryption and decryption assembly(DLL) used on the connection string value that is set in the webconfig file. The problem...
13
by: Tom Andrecht | last post by:
I'm trying to get some encryption/decryption routines going to take care of my data, and while the encryption is working great, I keep running into the message "Padding is invalid and cannot be...
5
by: Netwatcher | last post by:
well, i started messing around with dictionaries, yet, most of the pages i found about them always talk about getting only one word out of it and turning it vice versa, i've been playing with that...
9
by: Betikci Boris | last post by:
I get bored last night and wrote a script that uses xor for encrypt- decrypt, however it woks fine under linux 2.6.25, text and documents are ok, but fails on compressed files *.jpg, *.pdf , etc ....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.