另一台PC上的CryptoPP AES-256-CBC解密失败

问题描述 投票:0回答:1

我有适用于10多种不同PC的代码,但是在特定PC上无法运行,我不确定为什么。抛出的异常是StreamTransformationFilter: invalid PKCS #7 block padding found

数据在PHP中使用openssl_encrypt和AES-256-CBC方法在PHP中进行加密,解密是通过CryptoPP在客户端进行的。代码看起来像

std::string decrypt( const std::string& str_in, const std::string& key, const std::string& iv )
{
    std::string str_out;

    try
    {
        CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption decryption( ( byte* )key.data(), key.size(), ( byte* )iv.data() );

        CryptoPP::StringSource decryptor( str_in, true,
                                          new CryptoPP::StreamTransformationFilter( decryption,
                                          new CryptoPP::StringSink( str_out )
        )
        );
    }
    catch ( const CryptoPP::Exception& ex )
    { 
        MessageBox( NULL, ex.what(), qxor( "Decryption error" ), MB_ICONERROR | MB_OK );
    } 
    return str_out;
}

我很困惑为什么它可以在除1个人的计算机上的所有人之外工作。它们的key和iv不能错,所以这是不可能的,我将很高兴就如何调试此问题的建议提供任何提示,因为我已经为之困扰了很长时间。

c++ encryption crypto++
1个回答
0
投票

((我还不能发表评论)

您是否已确认key.size()的值在计算机之间是一致的?

    CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption decryption( ( byte* )key.data(), key.size(), ( byte* )iv.data() );
© www.soinside.com 2019 - 2024. All rights reserved.