Click here to Skip to main content
15,921,941 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Radio button Pin
Rage29-Jan-03 23:02
professionalRage29-Jan-03 23:02 
QuestionDelete History of Internet? Pin
xxhimanshu29-Jan-03 20:18
xxhimanshu29-Jan-03 20:18 
AnswerRe: Delete History of Internet? Pin
Abbas_Riazi29-Jan-03 22:08
professionalAbbas_Riazi29-Jan-03 22:08 
AnswerRe: Delete History of Internet? Pin
Rohit  Sinha30-Jan-03 1:51
Rohit  Sinha30-Jan-03 1:51 
GeneralRe: Delete History of Internet? Pin
xxhimanshu30-Jan-03 2:02
xxhimanshu30-Jan-03 2:02 
GeneralEncryption/Decryption Pin
Zaid Ansari29-Jan-03 19:28
Zaid Ansari29-Jan-03 19:28 
GeneralRe: Encryption/Decryption Pin
karl_w29-Jan-03 21:39
karl_w29-Jan-03 21:39 
GeneralRe: Encryption/Decryption Pin
Zaid Ansari29-Jan-03 22:03
Zaid Ansari29-Jan-03 22:03 
thanks karl,
i know that MD5 is a one way hash but i dont have any experiance in VC can u please tell me if i am making any mistake in this code.

to //code
if(!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL,0))
{
}
// Create a hash object.
if(!CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &hHash))
{
strcat(strErrorMessage, "Error executing CryptCreateHash");
return NULL;
}

if(!CryptHashData(hHash, (BYTE *)password, strlen(password), 0))
{
strcat(strErrorMessage, "Error executing CryptHashData");
return NULL;
}
// Derive a session key from the hash object.
if(!CryptDeriveKey(hCryptProv, CONST_ENCRYPT_ALGORITHM, hHash, 0, &hKey))
{
strcat(strErrorMessage, "Error executing CryptDeriveKey");
return NULL;
}

// Destroy the hash object.
CryptDestroyHash(hHash);
hHash = 0;

// Determine number of bytes to encrypt at a time.
// This must be a multiple of CONST_ENCRYPT_BLOCK_SIZE.
// CONST_ENCRYPT_BLOCK_SIZE is set by a #define statement.
dwBlockLen = 10 - 10 % CONST_ENCRYPT_BLOCK_SIZE;
// get data block as close to 1000 bytes as possible making sure it's a multiple of ENCRYPT_BLOCK_SIZE

// Determine the block size. If a block cipher is used,
// it must have room for an extra block.
if(CONST_ENCRYPT_BLOCK_SIZE > 1)
dwBufferLen = dwBlockLen + CONST_ENCRYPT_BLOCK_SIZE;
else
dwBufferLen = dwBlockLen;

// Allocate memory.
pbBuffer = (BYTE *)malloc(dwBufferLen);
BYTE *pAllBlocks = NULL;
BYTE *pPreviousBlocks = NULL;
bool fMoreDataExists = true;
DWORD dwIndex = 0;
DWORD dwLength;
DWORD dwLengthOfEncryptedData;
DWORD dwAllBlocksLength, dwPreviousBlocksLength;

// Make way through data one block at a time. Find out how big
// each encrypted string will be, allocate memory for it, and save
// in array.
do
{
// get next block of clear text data
GetBYTEDataBlockFromString(dwIndex, pClearTextString, dwBlockLen, pbBuffer, dwLength);
// check if more data exists after current block

if (dwIndex >= strlen(pClearTextString))
fMoreDataExists = false;

// encrypt current data block
dwLengthOfEncryptedData = dwLength;
if(!CryptEncrypt(hKey, 0, !fMoreDataExists, 0, pbBuffer, &dwLengthOfEncryptedData, dwBufferLen))
{
fout<<"Error Occured in CryptEncrypt";
}
if (pAllBlocks)
delete [] pAllBlocks;
if (pPreviousBlocks)
dwAllBlocksLength = dwPreviousBlocksLength + dwLengthOfEncryptedData;
else
dwAllBlocksLength = dwLengthOfEncryptedData;

pAllBlocks = new BYTE[dwAllBlocksLength];
if (!pAllBlocks)
{
if(pbBuffer)
free(pbBuffer);
if (pPreviousBlocks)
delete [] pPreviousBlocks;
strcat(strErrorMessage, "Unable to allocate memory for pAllBlocks");
FreeAllCryptHandles(hKey, hHash, hCryptProv);
return NULL;
}
// copy all encrypted data to pAllBlocks

if (pPreviousBlocks)
{
CopyBYTEData(dwPreviousBlocksLength, pPreviousBlocks, pAllBlocks, dwAllBlocksLength, 0);
CopyBYTEData(dwLengthOfEncryptedData, pbBuffer, pAllBlocks, dwAllBlocksLength, dwPreviousBlocksLength);
delete [] pPreviousBlocks;
}
else
CopyBYTEData(dwLengthOfEncryptedData, pbBuffer, pAllBlocks, dwAllBlocksLength, 0);

if (fMoreDataExists)
{ // save previous data blocks for next iteration of this do loop
dwPreviousBlocksLength = dwAllBlocksLength;
pPreviousBlocks = new BYTE[dwPreviousBlocksLength];
if (!pPreviousBlocks)
{
if(pbBuffer)
free(pbBuffer);
if (pAllBlocks)
delete [] pAllBlocks;
strcat(strErrorMessage, "Unable to allocate memory for pPreviousBlocks");
FreeAllCryptHandles(hKey, hHash, hCryptProv);
return NULL;
}
else
CopyBYTEData(dwAllBlocksLength, pAllBlocks, pPreviousBlocks, dwPreviousBlocksLength, 0);
}
}
while(fMoreDataExists);
GeneralRe: Encryption/Decryption Pin
Zaid Ansari29-Jan-03 22:05
Zaid Ansari29-Jan-03 22:05 
GeneralRe: Encryption/Decryption Pin
karl_w30-Jan-03 0:08
karl_w30-Jan-03 0:08 
GeneralRe: Encryption/Decryption Pin
Zaid Ansari30-Jan-03 0:46
Zaid Ansari30-Jan-03 0:46 
GeneralRe: Encryption/Decryption Pin
Zaid Ansari3-Feb-03 5:02
Zaid Ansari3-Feb-03 5:02 
GeneralRe: Encryption/Decryption Pin
karl_w3-Feb-03 6:28
karl_w3-Feb-03 6:28 
GeneralRe: Encryption/Decryption Pin
Zaid Ansari3-Feb-03 20:19
Zaid Ansari3-Feb-03 20:19 
GeneralPrecision of double type Pin
paulb29-Jan-03 19:12
paulb29-Jan-03 19:12 
GeneralRe: Precision of double type Pin
Chris Richardson29-Jan-03 19:49
Chris Richardson29-Jan-03 19:49 
GeneralSetting Bitmap Background for CProgressCtrl Pin
Effiniti29-Jan-03 18:09
Effiniti29-Jan-03 18:09 
GeneralRe: Setting Bitmap Background for CProgressCtrl Pin
Abbas_Riazi29-Jan-03 22:12
professionalAbbas_Riazi29-Jan-03 22:12 
GeneralVisual C++ terms and agreements Pin
moraalg29-Jan-03 16:52
moraalg29-Jan-03 16:52 
GeneralRe: Visual C++ terms and agreements Pin
Christian Graus29-Jan-03 18:09
protectorChristian Graus29-Jan-03 18:09 
Generalspecial .lnk files Pin
Hervorzaubern29-Jan-03 14:01
Hervorzaubern29-Jan-03 14:01 
GeneralRe: special .lnk files Pin
Chris Losinger29-Jan-03 14:19
professionalChris Losinger29-Jan-03 14:19 
GeneralRe: special .lnk files Pin
30-Jan-03 5:41
suss30-Jan-03 5:41 
GeneralRe: special .lnk files Pin
Hervorzaubern30-Jan-03 5:42
Hervorzaubern30-Jan-03 5:42 
Generalclistctrl in report mode: make the header not clickable. Pin
trustno129-Jan-03 14:01
trustno129-Jan-03 14:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.