サンプルコードをcrypto ++ライブラリにダウンロードしました。私はそのコードをテストし、結果としてHEXコードのグループを返します。私はブラウザに暗号化されたテキストとしてユーザーIDを送信したい。特定のユーザーの詳細を表示する要求が出されたら、要求テキストを復号化してユーザーIDを見つけ、そのユーザーのデータを処理し、その応答をブラウザーに送信する必要があります。しかし、次のコードを使用すると、chipperテキストはHEX値のグループとして取得されます。私はこのチッパーテキストをSHA値のように20〜25文字程度の長さにしたいと思っています。 SHA値などのチッパーテキストを変更するにはどうすればよいですか?ウェブでcrypto ++コードを使用する方法
//Key and IV setup
//AES encryption uses a secret key of a variable length (128-bit, 196-bit or 256-
//bit). This key is secretly exchanged between two parties before communication
//begins. DEFAULT_KEYLENGTH= 16 bytes
byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE ];
memset(key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH);
memset(iv, 0x00, CryptoPP::AES::BLOCKSIZE);
//
// String and Sink setup
//
std::string plaintext = "Now is the time for all good men to come to the aide...";
std::string ciphertext;
std::string decryptedtext;
//
// Dump Plain Text
//
std::cout << "Plain Text (" << plaintext.size() << " bytes)" << std::endl;
std::cout << plaintext;
std::cout << std::endl << std::endl;
//
// Create Cipher Text
//
CryptoPP::AES::Encryption aesEncryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH);
CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, iv);
CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::StringSink(ciphertext));
stfEncryptor.Put(reinterpret_cast<const unsigned char*>(plaintext.c_str()), plaintext.length() + 1);
stfEncryptor.MessageEnd();
//
// Dump Cipher Text
//
std::cout << "Cipher Text (" << ciphertext.size() << " bytes)" << std::endl;
for(int i = 0; i < ciphertext.size(); i++) {
std::cout << "0x" << std::hex << (0xFF & static_cast<byte>(ciphertext[i])) << " ";
}
std::cout << std::endl << std::endl;
//
// Decrypt
//
CryptoPP::AES::Decryption aesDecryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH);
CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption(aesDecryption, iv);
CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new CryptoPP::StringSink(decryptedtext));
stfDecryptor.Put(reinterpret_cast<const unsigned char*>(ciphertext.c_str()), ciphertext.size());
stfDecryptor.MessageEnd();
//
// Dump Decrypted Text
//
std::cout << "Decrypted Text: " << std::endl;
std::cout << decryptedtext;
std::cout << std::endl << std::endl;
出力:
Plain Text (55 bytes)
Now is the time for all good men to come to the aide...
Cipher Text (64 bytes)
0x7f 0xf8 0xb3 0xea 0x8a 0x2 0xb3 0x7a 0x3d 0x28 0x66 0x9c 0x97 0x13 0xa7 0xb3 0xf 0xa2 0x50 0x25 0x80 0xd5 0xd2 0x32 0xce 0xe8 0xa 0x57 0x33 0xef 0x70 0xff 0x48 0xe9 0xe8 0x4 0x98 0xa9 0x4 0xc2 0x5e 0xa7 0xb0 0x40 0x43 0xa1 0xfc 0x23 0xb1 0xa1 0xeb 0x1e 0xb2 0xf6 0x97 0x62 0x70 0xa1 0x81 0xca 0x6e 0x78 0x80 0x90
Decrypted Text:
Now is the time for all good men to come to the aide...
しかし、私は、テキストをチッパーたい、
kdHkekdKLI!kdheGHWewqef