2013-01-25 104 views
0

我正在使用BouncyCastle軟件包進行OpenPGP加密。 除了一部分以外,一切都很順利。當我將加密文本寫入文件時,它會附加下面的消息BouncyCastle在加密文件中自動添加簽名

-----BEGIN PGP MESSAGE----- 
Version: BCPG v1.47 
//encrypted text here 
-----END PGP MESSAGE----- 

但是我不想在文件中籤名部分。 下面是我使用的加密

public void encryptFile(OutputStream out, String fileName, PGPPublicKey encKey, boolean armor, boolean withIntegrityCheck) throws IOException, NoSuchProviderException, PGPException { 
      //armor = true; integrityCheck = true 
    Security.addProvider(new BouncyCastleProvider()); 

    if (armor) { 
     out = new ArmoredOutputStream(out); 
    } 

    ByteArrayOutputStream bOut = new ByteArrayOutputStream(); 
    PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(PGPCompressedData.ZIP); 

    PGPUtil.writeFileToLiteralData(comData.open(bOut), PGPLiteralData.BINARY, new File(fileName)); 

    comData.close(); 

    BcPGPDataEncryptorBuilder dataEncryptor = new BcPGPDataEncryptorBuilder(PGPEncryptedData.AES_256); 
    dataEncryptor.setWithIntegrityPacket(withIntegrityCheck); 
    dataEncryptor.setSecureRandom(new SecureRandom()); 

    PGPEncryptedDataGenerator encryptedDataGenerator = new PGPEncryptedDataGenerator(dataEncryptor); 
    encryptedDataGenerator.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(encKey)); 

    byte[] bytes = bOut.toByteArray(); 
    OutputStream cOut = encryptedDataGenerator.open(out, bytes.length); 
    cOut.write(bytes); 
    cOut.close(); 
    out.close(); 
} 

回答

3

代碼這不是簽名,但是對於裝甲數據的信封。關閉裝甲,你會得到二進制加密數據。如果你移除信封並繼續裝甲,那麼OpenPGP工具的符合性解密將不知道該怎麼做 - 它們將無法區分裝甲和非裝甲數據。