BouncyCastle 最后字节解密问题
我正在使用 Bouncy Castle 从文件系统解密 XML 文件。 我输出解密的文本,并在数据的最后一个字节上收到致命错误 SAXParseException。 下面是我的解密方法和密码对象的设置。
我最初使用的是密码流,一切都很完美(注释掉的代码是我的流)。 由于策略文件和最终用户没有 256 位无限版本,我需要使用充气城堡。
有什么想法为什么最后一个字节没有通过吗?
来自构造函数:
keyParam = new KeyParameter(key);
engine = new AESEngine();
paddedBufferedBlockCipher =
new PaddedBufferedBlockCipher(new CBCBlockCipher(engine));
解密方法:
public void decrypt(InputStream in, OutputStream out) {
try
{
paddedBufferedBlockCipher.init(false,
new ParametersWithIV(keyParam, _defaultIv));
// cipher.init(Cipher.DECRYPT_MODE, secretKey, ivs);
// CipherInputStream cipherInputStream
// = new CipherInputStream(in, cipher);
byte[] buffer = new byte[4096];
byte[] outBuffer = new byte[4096];
for (int count = 0; (count = in.read(buffer)) != -1;) {
paddedBufferedBlockCipher.processBytes(buffer, 0,
count, outBuffer, 0);
out.write(outBuffer, 0, count);
}
}
catch(Exception e) {
e.printStackTrace();
}
}
[Fatal Error] :40:23: Element type "Publi" must be followed by either attribute specifications, ">" or "/>".
org.xml.sax.SAXParseException: Element type "Publi" must be followed by either attribute specifications, ">" or "/>".
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:264)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
I am decrypting an XML file from the file system using Bouncy Castle. I output the decrypted text and get a fatal error SAXParseException on the very last byte of data. Below is my decryption method and the setup of the cipher object.
I was initially using cipher streams, and everything worked perfect (commented out code was my stream). Due to policy files and end users not having the 256 bit unlimited versions I need to use bouncy castle.
Any ideas why the final byte is not coming through?
From Constructor:
keyParam = new KeyParameter(key);
engine = new AESEngine();
paddedBufferedBlockCipher =
new PaddedBufferedBlockCipher(new CBCBlockCipher(engine));
Decrypt Method:
public void decrypt(InputStream in, OutputStream out) {
try
{
paddedBufferedBlockCipher.init(false,
new ParametersWithIV(keyParam, _defaultIv));
// cipher.init(Cipher.DECRYPT_MODE, secretKey, ivs);
// CipherInputStream cipherInputStream
// = new CipherInputStream(in, cipher);
byte[] buffer = new byte[4096];
byte[] outBuffer = new byte[4096];
for (int count = 0; (count = in.read(buffer)) != -1;) {
paddedBufferedBlockCipher.processBytes(buffer, 0,
count, outBuffer, 0);
out.write(outBuffer, 0, count);
}
}
catch(Exception e) {
e.printStackTrace();
}
}
[Fatal Error] :40:23: Element type "Publi" must be followed by either attribute specifications, ">" or "/>".
org.xml.sax.SAXParseException: Element type "Publi" must be followed by either attribute specifications, ">" or "/>".
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:264)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你打电话doFinal() 与最后的数据块?
Do you call doFinal() with the final chunk of data?