ต้อง Gen Key Pair (Public/Private Key) ก่อน มีในตัวอย่าง CryptoPP อยู่แล้ว
//Encrypt
BYTE * _Buff = new BYTE[1024 * 1000];
CryptoPP::ArraySink * _WriteBuffer = new CryptoPP::ArraySink( _Buff,1024 * 1000);
DWORD Test1 = 1;
_WriteBuffer->PutWord32(Test1 );
CryptoPP::FileSource privFile("public_file.key", true, new CryptoPP::HexDecoder);
CryptoPP::RSAES_OAEP_SHA_Encryptor pub(privFile);
CryptoPP::RandomPool randPool;
randPool.IncorporateEntropy((byte *)"_SEED", 1);
CryptoPP::ArraySource(_Buff,_WriteBuffer->TotalPutLength(), true, new CryptoPP::PK_EncryptorFilter(randPool, pub, (new CryptoPP::FileSink("encrypted.dat") )));
//Decrypt
//Start dec
CryptoPP::FileSource privFile2("private_file.key", true, new CryptoPP::HexDecoder);
CryptoPP::RSAES_OAEP_SHA_Decryptor priv(privFile2);
BaseCrypto bc;
CryptoPP::ByteQueue * _bq = new CryptoPP::ByteQueue();
CryptoPP::FileSource DataFile("encrypted.dat", true, (new CryptoPP::PK_DecryptorFilter(bc.GlobalRNG(), priv, _bq )));
CryptoPP::word32 Test1= 0;
size_t _ret = _bq->GetWord32(Test1); //Test1 = 1
ไม่มีความคิดเห็น:
แสดงความคิดเห็น