OpenSSL 라이브러리로 Blowfish 암호화를 받아야합니다. 그러나 뭔가가 작동하지 않습니다.
내가 뭘 잘못하고 있니? 나는 이런 식으로 할 노력하고있어 :OpenSSL을 사용하여 Blowfish에 메시지를 암호화하는 방법은 무엇입니까?
#include <iostream>
#include <openssl/blowfish.h>
#include "OpenSSL_Base64.h"
#include "Base64.h"
using namespace std;
int main()
{
unsigned char ciphertext[BF_BLOCK];
unsigned char plaintext[BF_BLOCK];
// blowfish key
const unsigned char *key = (const unsigned char*)"topsecret";
//unsigned char key_data[10] = "topsecret";
BF_KEY bfKey;
BF_set_key(&bfKey, 10, key);
/* Open SSL's Blowfish ECB encrypt/decrypt function only handles 8 bytes of data */
char a_str[] = "8 Bytes";//{8, ,B,y,t,e,s,\0}
char *arr_ptr = &a_str[0];
//unsigned char* data_to_encrypt = (unsigned char*)"8 Bytes"; // 7 + \0
BF_ecb_encrypt((unsigned char*)arr_ptr, ciphertext, &bfKey, BF_ENCRYPT);
unsigned char* ret = new unsigned char[BF_BLOCK + 1];
strcpy((char*)ret, (char*)ciphertext);
ret[BF_BLOCK + 1] = '\0';
char* base_enc = OpenSSL_Base64::Base64Encode((char*)ret, strlen((char*)ret));
cout << base_enc << endl;
cin.get();
return 0;
}
을하지만 잘못된 출력을 얻을 :
fy7maf+FhmbM
내가 그것으로 확인 :
http://sladex.org/blowfish.js/
그것은되어야한다 : fEcC5를/EKDVY =
Base64 :
01 23,516,
이 질문은 여러 번 요청되었습니다. [openssl blowfish encryption example site : stackoverflow.com ] (http://www.google.com/search?q=openssl+blowfish+encryption+example+site%3Astackoverflow.com). 'strlen ((char *) ciphertext'는 *** 않습니다 *** 않습니다. OpenSSL 위키에서 [EVP Symmetric Encryption and Decryption] (http://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption)을 참조하십시오. 심지어 C++에서 사용하는 예제도 제공합니다 .. – jww
질문을하고 2 일 동안 github에서 검색하십시오. 내가 찾은 것이 전부이거나 불완전한 결과이므로 처음부터 시작했습니다. 이해하려고 노력 중입니다 – Vadim
물론 Blowfish는 새로운 작업 인 AES 현재 선택입니다. – zaph