Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / September 2004

Tip: Looking for answers? Try searching our database.

decryption code  throwing a hissyfit.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hazz - 13 Sep 2004 22:25 GMT
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*
hazz - 14 Sep 2004 21:09 GMT
if szStringToDecrypt is shorter than the offending input string to encrypt,
as when "test" is the encrypted string,  no problem.

> Here is a method that throws a NullReferenceException at the line pointed to
> below . szCharKey is undefined at that point.
[quoted text clipped - 68 lines]
>
> szStringToDecrypt =

"5E45D91532071793F87E543E6DF59A6A792F9790918F6D2F1D80D3D9D34B9DA92DB536343C7

D71A371F68485271A9B6AD57CDD654770C015852A78E573551FDFD0B40529DB28CD6A55F3098

02488212CEB9A15C5C1CC464826D05762D83B0989AA8AD26F5748A93FC853820319423ABE788

8571058CCEC9D46DC22F8F42BA7550ADE3E857D5F86FBD3E3415B885E9489058D635FBF2DD49

96EA62302F6A84AC997C42936CA3A2BFB631D10D7542E6B267D302A1F93D40F4926CB929FE81

FD66AAB96D7F0F1B51ACCC5C74C0C4B0AAE240C3CD0A2AEBA45F44D02771D584353969E9CBD3

F00E99F5CF7797B06F7D4350EABA81A4CEDCD288FE38445817237936621E367791EE49CC09DB

C6227600CF361923B2BDF81E96496B103A17B6884C985E48559B4DA50B266B4438A5E2A8762E

70A0CFED667F0677E717CF14014C9D4429F694D2A0654B6E13A612B7B40EF3E122B01992640C

3C6484B493A293BA4FB9AEFCA94F3BD2365FAAF917358F3AA67FE9FD15B978FDF772E3EC3A77

246A3D70996449DCBC145FE83FBA54F653EB5E60D624D48508505AAB612AEC0E115F5F47D7A5
> CDE68F22662F1D693A133337B2C512957D2C4F0DA84D9"
>
> pszIn  = 0x001bfb70

"8D1E82F58E8953AD3ED791461570E2D57E8DB057CEB5BC4E174B466354E04FE3D091A03F1E4

7612BCC7CB4409AF6BB44B06277F4D065ABD70B204B23CE94010D1DEB5B443664BCDF3B7BE04

59C45DCD80B03B232040A5267225882E510CB45966F1EDD9B0323EAC7BC8FD36993B34899210
> 2303570420323A967DB1517D8F99H" char*

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.