我工作的概念Java应用程序的证明,上面写着一系列从PGP加密文件换行分隔的请求,处理这些请求,然后写入到另一个PGP加密文件中的响应,每个响应写后冲水。
我已经成功地集成充气城堡1.5与我与我似乎无法刷新的命令输出中的例外适用:
private ArmoredOutputStream armoredOut = null;
private OutputStream compressedOut = null;
private OutputStream encryptedOut = null;
public OutputStream encryptStream(OutputStream outputStream){
OutputStream literalOut = null;
try{
armoredOut = new ArmoredOutputStream(outputStream);
BcPGPDataEncryptorBuilder dataEncryptor = new BcPGPDataEncryptorBuilder(PGPEncryptedData.AES_256);
dataEncryptor.setSecureRandom(new SecureRandom());
PGPEncryptedDataGenerator encryptGen = new PGPEncryptedDataGenerator(dataEncryptor);
PGPPublicKey publicKey = null;
InputStream publicKeyStream = null;
try{
publicKeyStream = this.getClass().getClassLoader().getResourceAsStream(keyName);
publicKey = getEncryptionKey(publicKeyStream);
}
finally{
if(publicKeyStream != null){
publicKeyStream.close();
}
}
if(publicKey == null){
throw new IllegalArgumentException("Couldn't obtain public key.");
}
encryptGen.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(publicKey));
encryptedOut = encryptGen.open(armoredOut, new byte[bufferSize]);
PGPCompressedDataGenerator compressGen = new PGPCompressedDataGenerator(PGPCompressedData.ZIP);
compressedOut = compressGen.open(encryptedOut);
PGPLiteralDataGenerator literalGen = new PGPLiteralDataGenerator();
literalOut = literalGen.open(compressedOut, PGPLiteralDataGenerator.UTF8, "Response", new Date(), new byte[bufferSize]);
}
catch(PGPException e){
LOGGER.error(ExceptionUtils.getStackTrace(e));
}
catch(IOException e){
LOGGER.error(ExceptionUtils.getStackTrace(e));
}
return literalOut;
}
当我明确调用flush返回的OutputStream不刷新()。 只有当close()方法被调用在每个compressedOut,encryptedOut和armoredOut OutputStreams的是他们居然脸红。
我试图修改充气城堡的源代码,但我所做的一切导致了某种畸形或损坏的PGP消息不能被解密。 我也试着修改缓冲区大小,以使其更小,大,单个请求的具体规模,但没有奏效。
有没有人对如何手动刷新与充气城堡加密的OutputStream有什么建议?