+-
c#-使用Blowfish / CBC / PKCS5Padding加密和解密数据
遗留应用程序(ColdFusion)使用Blowfish / CBC / PKCS5Padding加密.我们如何使用BouncyCastle库对数据进行加密和解密?

对于其他字段,使用以下方法在ColdFusion中加密:

encrypt( data, key, 'BLOWFISH', 'HEX')

我们使用此代码

BlowfishEngine engine = new BlowfishEngine();
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(engine);
cipher.Init(false, new KeyParameter(Convert.FromBase64String(keyString)));
byte[] out1 = Hex.Decode(name);
byte[] out2 = new byte[cipher.GetOutputSize(out1.Length)];
int len2 = cipher.ProcessBytes(out1, 0, out1.Length, out2, 0);
cipher.DoFinal(out2, len2);
return Encoding.UTF8.GetString(out2);

问题是如何解密在ColdFusion中加密的内容,如下所示:

encrypt( data, Key, "Blowfish/CBC/PKCS5Padding", "base64", IV )
最佳答案
我想到了.如果有人感兴趣:

        BlowfishEngine engine = new BlowfishEngine();
        var cipher = new PaddedBufferedBlockCipher( new CbcBlockCipher( engine ), new Pkcs7Padding() );
        StringBuilder result = new StringBuilder();
        cipher.Init( false, new ParametersWithIV( new KeyParameter( Convert.FromBase64String( keyString ) ), System.Text.Encoding.ASCII.GetBytes( IV ) ) );
        byte[] out1 = Convert.FromBase64String( name );
        byte[] out2 = new byte[ cipher.GetOutputSize( out1.Length ) ];
        int len2 = cipher.ProcessBytes( out1, 0, out1.Length, out2, 0 );
        cipher.DoFinal( out2, len2 );
        return Encoding.UTF8.GetString( out2 );
点击查看更多相关文章

转载注明原文:c#-使用Blowfish / CBC / PKCS5Padding加密和解密数据 - 乐贴网