私はBouncy Castleを使用してファイルシステムからXMLファイルを解読しています。私は復号化されたテキストを出力し、データの最後のバイトで致命的なエラーSAXParseExceptionを取得します。以下は私の解読方法と暗号オブジェクトの設定です。BouncyCastle最終バイト解読の問題
私は当初暗号ストリームを使用していましたが、すべてが完璧に機能しました(コメントアウトされたコードはストリームでした)。ポリシーファイルとエンドユーザーが256ビット無制限のバージョンを持っていないため、私はバウンシーキャッスルを使用する必要があります。
最後のバイトが通っていない理由は何ですか?データの最後のチャンクと
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()は必要なく、うまくいくと仮定しました。私は "カウント"変数のシステムを実行し、最後の数字が何であるかを確認します –
間違っています: "バッファの最後のブロックを処理します。バッファが現在いっぱいで、**パディングを追加する必要があります**コールtoFinalは2 * getBlockSize()バイトを生成します。 " – akarnokd