一种传统的应用程序(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 )