【问题标题】:Encrypt and Decrypt data using Blowfish/CBC/PKCS5Padding使用 Blowfish/CBC/PKCS5Padding 加密和解密数据
【发布时间】:2019-05-15 06:30:07
【问题描述】:

旧版应用程序 (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 )

【问题讨论】:

    标签: c# encryption coldfusion bouncycastle blowfish


    【解决方案1】:

    我想通了。如果有人感兴趣:

            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 );
    

    【讨论】:

      猜你喜欢
      • 2015-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-28
      • 2019-09-09
      • 2021-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多