English 中文(简体)
C区没有解密来自爪哇的 最终解密的博恩西城堡 #
原标题:Bouncy Castle Not Decrypting DoFinal from Java in C#

我正在尝试解密使用爪哇邦西城堡图书馆加密的数据。 以爪哇( 与蓬西城堡图书馆一起) 加密的数据可以用爪哇解密 。 我使用相同的密钥和参数, 但当我到达DoFinal时, 我得到错误“ 封堵被损坏 ” 。

这里是爪哇:

KeyParameter keyParam = new KeyParameter(key);
CipherParameters param = new ParametersWithIV(keyParam, initVector);

BlockCipherPadding padding = new PKCS7Padding();
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), padding);
cipher.reset();
cipher.init(true, param);

byte[] fileBytes = Base64.decodeBase64(decryptedStringData);
byte[] encrypted = new byte[cipher.getOutputSize(fileBytes.length)];
int l = cipher.processBytes(fileBytes, 0, fileBytes.length, encrypted, 0);
l += cipher.doFinal(encrypted, l);

return (Base64.encodeBase64String(encrypted));

这是C#:

KeyParameter keyParam = new KeyParameter(key);
ICipherParameters param = new ParametersWithIV(keyParam, initVector);

IBlockCipherPadding padding = new Pkcs7Padding();
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CbcBlockCipher(new AesEngine()), padding);
cipher.Reset();
cipher.Init(false, param);

byte[] fileBytes = Convert.FromBase64String(encryptedDataString);
byte[] decrypted = new byte[cipher.GetOutputSize(fileBytes.Length)];
int l = cipher.ProcessBytes(fileBytes, 0, fileBytes.Length, decrypted, 0);
l += cipher.DoFinal(decrypted, l);

return(Convert.ToBase64String(decrypted));

我制作了32字节的 PBK 键盘, 以一个被缓冲的大麻为基础... 然而,我们检查了爪哇和C#之间生成的钥匙, 它们是一样的。

最佳回答

结果发现为加密和解密提供的数据是以不同格式编码的。 我正以 UTF-8 编码字符串来解密, 需要先将其输入 Base64 字符串。 感谢您提供的所有帮助 。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签