gpt4 book ai didi

java - BouncyCaSTLe 最后一个字节解密问题

转载 作者:搜寻专家 更新时间:2023-11-01 03:30:29 24 4
gpt4 key购买 nike

我正在使用 Bouncy CaSTLe 从文件系统解密 XML 文件。我输出解密的文本,并在数据的最后一个字节上收到 fatal error 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)

最佳答案

你调用doFinal吗? () 和最后的数据 block ?

public void decrypt(InputStream in, OutputStream out) {
try
{
paddedBufferedBlockCipher.init(false,
new ParametersWithIV(keyParam, _defaultIv));
byte[] buffer = new byte[4096];
byte[] outBuffer = new byte[4096];

for (int count = 0; (count = in.read(buffer)) != -1;) {
int c2 = paddedBufferedBlockCipher.processBytes(buffer, 0,
count, outBuffer, 0);
out.write(outBuffer, 0, c2);
}
count = paddedBufferedBlockCipher.doFinal(outBuffer, 0);
out.write(outBuffer, 0, count);
}
catch(Exception e) {
e.printStackTrace();
}
}

关于java - BouncyCaSTLe 最后一个字节解密问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1188732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com