
Новые сообщения [новые:0]
Дайджест
Горячие темы
Избранное [новые:0]
Форумы
Пользователи
Статистика
Статистика нагрузки
Мод. лог
Поиск
|
|
26.04.2006, 12:11
|
|||
|---|---|---|---|
Дешифровка данных из файла в память |
|||
|
#18+
У меня есть зашифрованный файл (процедура, изменяющая БД) (хэш). Мне нужно считать оттуда данные. Их дешифровать и обновить БД. Но дешифрованные данные не должны нигде сохраняться постоянно. т.е. считать из файла, дешифровать их (в память(CMemFile) или в строку) и обновить БД. А файл сам должен остаться зашифрованным. Как мне лучше это сделать? Сейчас я использую так: //Get handle to the default provider if ( ! CryptAcquireContext( &hCryptProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, 0)) { AfxMessageBox("Ошибка при выполнении CryptAcquireContext!"); return FALSE; } //Create a hash object if ( !CryptCreateHash( hCryptProv, CALG_MD5, 0, 0, &hHash)) { AfxMessageBox("Ошибка при выполнении CryptCreateHash!"); return FALSE; } //Hash the password if( !CryptHashData( hHash, (BYTE *)"Some Common Data", sizeof("Some Common Data"), 0)) { AfxMessageBox("Ошибка при выполнении CryptHashData!"); return FALSE; } //derive a session key from the hash object if ( ! CryptDeriveKey( hCryptProv, ENCRYPT_ALGORITHM /*CALG_RC2*/, hHash, /*KEYLENGTH*/ CRYPT_EXPORTABLE, &hKey)) { CString str; str.AppendFormat("%x", GetLastError()); AfxMessageBox("Ошибка при выполнении CryptDeriveKey!"); return FALSE; } //destroy the hash object CryptDestroyHash(hHash); hHash = 0 ; //-------------------------------------------------------------------- // The session key is now ready. If it is not a key derived from a // password, the session key encrypted with the encrypter's private // key has been written to the destination file. //-------------------------------------------------------------------- // Determine number of bytes to encrypt at a time. // This must be a multiple of ENCRYPT_BLOCK_SIZE. // ENCRYPT_BLOCK_SIZE is set by a #define statement. dwBlockLen = 1000 - 1000 % ENCRYPT_BLOCK_SIZE; //-------------------------------------------------------------------- // Determine the block size. If a block cipher is used, // it must have room for an extra block. if(ENCRYPT_BLOCK_SIZE > 1) dwBufferLen = dwBlockLen + ENCRYPT_BLOCK_SIZE; else dwBufferLen = dwBlockLen; //Allocate memory if (! (pbBuffer = (BYTE *)malloc(dwBufferLen))) { AfxMessageBox("Ошибка при выделении памяти!"); return FALSE; } // In a do loop, encrypt the source file and write to the source file. do { //-------------------------------------------------------------------- // Read up to dwBlockLen bytes from the source file. dwCount = fread(pbBuffer, 1, dwBlockLen, hSource); if(ferror(hSource)) { AfxMessageBox("Ошибка при чтении незашифрованного текста!"); return FALSE; } // Encrypt data. if(!CryptEncrypt( hKey, 0, feof(hSource), 0, pbBuffer, &dwCount, dwBufferLen)) { AfxMessageBox("Ошибка при выполнении CryptEncrypt!"); return FALSE; } ... |
|||
|
:
Нравится:
Не нравится:
|
|||
|
|
|

start [/forum/topic.php?fid=57&mobile=1&tid=2031436]: |
0ms |
get settings: |
6ms |
get forum list: |
17ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
205ms |
get topic data: |
9ms |
get forum data: |
2ms |
get page messages: |
25ms |
get tp. blocked users: |
1ms |
| others: | 218ms |
| total: | 489ms |

| 0 / 0 |
