SHA256을 사용하여 키로 사용하는 문자열을 해시했지만이 키를 사용하여 CBC 모드 및 crypto ++에서 AES로 문자열을 암호화하려면 어떻게해야합니까? 감사.
아래 코드로 원하는 결과를 얻었습니다.
QString qhash = "hash";
std::string plain = "message";
std::string ciphertext;
std::string stdhash = qhash.toStdString();
CryptoPP::HexDecoder decoder;
decoder.Put((byte*)stdhash.data(),qhash.size());
decoder.MessageEnd();
CryptoPP::word64 size = decoder.MaxRetrievable();
char *decodedKey = new char[size];
decoder.Get((byte *)decodedKey, size);
byte hash[CryptoPP::AES::MAX_KEYLENGTH], iv[ CryptoPP::AES::BLOCKSIZE ];
CryptoPP::StringSource(reinterpret_cast<const char *>(decodedKey), true,new CryptoPP::ArraySink(hash, CryptoPP::AES::MAX_KEYLENGTH));
memset(iv, 0x00, CryptoPP::AES::BLOCKSIZE);
CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption Encryptor(hash,sizeof(hash),iv);
CryptoPP::StringSource( plain, true, new CryptoPP::StreamTransformationFilter( Encryptor, new CryptoPP::HexEncoder(new CryptoPP::StringSink( ciphertext )) ) );
return ciphertext;
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다