c++怎么处理java AES SHA1PRNG 加密的数据, 最近对接接口,由于我不会java,所以用c++来写,但是java AES SHA1PRNG 对密钥做了两次sha1.。。。。导致一直解不出来,百du找的全是水文,无奈自己用CryptoPP做了一下解密 std::string AESSha1Prng::aesDecrypt(const std::string &ciphertext, std::string key) { //处理java SHA1PRNG密钥 两次sha1后截取前32。。。。。 std::string output; while (output.size() < 16) { //16对应32 CryptoPP::byte hash[CryptoPP::SHA1::DIGESTSIZE]; CryptoPP::SHA1().CalculateDigest(hash, (CryptoPP::byte *) key.data(), key.size()); key.assign((char *) hash, CryptoPP::SHA1::DIGESTSIZE); CryptoPP::SHA1().CalculateDigest(hash, (CryptoPP::byte *) key.data(), key.size()); key.assign((char *) hash, CryptoPP::SHA1::DIGESTSIZE); output += key; } std::string key1 = output.substr(0, 16); //用处理过的key解密数据 CryptoPP::SecByteBlock aesKey(reinterpret_cast<const CryptoPP::byte *>(key1.data()), key1.size()); CryptoPP::ECB_Mode<CryptoPP::AES>::Decryption decryption; decryption.SetKey(aesKey, aesKey.size()); std::string decryptedText; CryptoPP::StringSource stringSource(ciphertext, true, new CryptoPP::Base64Decoder( new CryptoPP::StreamTransformationFilter(decryption, new CryptoPP::StringSink( decryptedText) ) ) ); return decryptedText; } |