Encrypt/Decrypting Files (CR & LF chars not correct in .exes)
-
Hi folks, I am writting a program that Encrypts/Decrypts files (using CFile). It works fine when I do Text files, but when I do an .exe (Decrypting), it puts a different char?? could this have to do with the way I'm reading in the File (mode)? I have tried using it in Binary Mode and still the same! NOTE: All of the characters (placement) are correct, its just that in the .exe there is NOT all of the little rectangular chars...its empty (visually) space (see below). =========================================================== MZÿÿ¸@躴 Í!¸LÍ!This program cannot be run in DOS mode. =========================================================== Here is some code: // Open the file to be read if( cfEnFile.Open( LPCTSTR(csFileName), CFile::modeReadWrite | CFile::typeBinary, &e ) ) { // Get the length of the file DWORD dwSize = cfEnFile.GetLength(); cfEnFile.SeekToBegin(); // fill the buffer with the information from file UINT nBytesRead = cfEnFile.Read( szBufRead, (UINT)dwSize); //(UINT) dwSize ); ... ... ... for (int n=0; n<(int)nBytesRead; n++) { CString csEnByte = szBufRead[n]; m_AESCrypt.TransformString(csRegUPPRead, csEnByte); csBufBytes += csEnByte; } sprintf(szBufWrite, "%s", csBufBytes); cfEnFile.SeekToBegin(); // Write the buffer to the file cfEnFile.Write( szBufWrite, (UINT)dwSize); } Is there anyone who can help!!!!! Thanks in advance! Dan
-
Hi folks, I am writting a program that Encrypts/Decrypts files (using CFile). It works fine when I do Text files, but when I do an .exe (Decrypting), it puts a different char?? could this have to do with the way I'm reading in the File (mode)? I have tried using it in Binary Mode and still the same! NOTE: All of the characters (placement) are correct, its just that in the .exe there is NOT all of the little rectangular chars...its empty (visually) space (see below). =========================================================== MZÿÿ¸@躴 Í!¸LÍ!This program cannot be run in DOS mode. =========================================================== Here is some code: // Open the file to be read if( cfEnFile.Open( LPCTSTR(csFileName), CFile::modeReadWrite | CFile::typeBinary, &e ) ) { // Get the length of the file DWORD dwSize = cfEnFile.GetLength(); cfEnFile.SeekToBegin(); // fill the buffer with the information from file UINT nBytesRead = cfEnFile.Read( szBufRead, (UINT)dwSize); //(UINT) dwSize ); ... ... ... for (int n=0; n<(int)nBytesRead; n++) { CString csEnByte = szBufRead[n]; m_AESCrypt.TransformString(csRegUPPRead, csEnByte); csBufBytes += csEnByte; } sprintf(szBufWrite, "%s", csBufBytes); cfEnFile.SeekToBegin(); // Write the buffer to the file cfEnFile.Write( szBufWrite, (UINT)dwSize); } Is there anyone who can help!!!!! Thanks in advance! Dan
Since you indicate that it works with TEXT files but not EXE files, likely there is a 7 bit character dependancy within your code. However I can not see that from the code that you have posted. Possibly something within the 'TransformString' method is not dealing with the 8th bit correctly. HTH.
-
Since you indicate that it works with TEXT files but not EXE files, likely there is a 7 bit character dependancy within your code. However I can not see that from the code that you have posted. Possibly something within the 'TransformString' method is not dealing with the 8th bit correctly. HTH.
Hey Dan, Not to burst your bubble or anything, but posting an encryption hash algorithm with full commenting to the Web is not going to make your program very secure. (Or I suppose you trust us fellow programmers!) Anyway, I suppose it won't hurt, since this cryptography scheme is already published in "Applied Cryptography." Brian Hart