0

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();
}
4

1 に答える 1

3

これは署名ではなく、装甲データの封筒です。アーマーをオフにすると、バイナリ暗号化されたデータが得られます。エンベロープを削除して防御を維持すると、OpenPGP ツールを復号化する適合者は、これをどう処理するかわかりません。防御されたデータと防御されていないデータを区別できなくなります。

于 2013-01-25T06:40:03.473 に答える