使用Bouncy Castle(Java)和GPG4Win加密时文件大小不同

使用Bouncy Castle(Java)和GPG4Win加密时文件大小不同,java,encryption,size,rsa,bouncycastle,Java,Encryption,Size,Rsa,Bouncycastle,问题是: 我使用Bouncy Castle Java库对文件进行加密,但我得到的加密文件的大小比使用其他实用程序(如GPG4Win、FileAssurance)时大得多。 与我的代码生成的文件相比,这些实用程序生成的加密文件大小非常小 我想知道使用RSA公钥和DSA公钥时是否有不同的加密方式 其他信息: 公钥证书类型:2047位RSA 我用来加密数据文件的代码被读取并作为字节数组传递: private static byte[] encrypt(byte[] clearData, PGPPubl

问题是: 我使用Bouncy Castle Java库对文件进行加密,但我得到的加密文件的大小比使用其他实用程序(如GPG4Win、FileAssurance)时大得多。 与我的代码生成的文件相比,这些实用程序生成的加密文件大小非常小

我想知道使用RSA公钥和DSA公钥时是否有不同的加密方式

其他信息:

公钥证书类型:2047位RSA

我用来加密数据文件的代码被读取并作为字节数组传递:

private static byte[] encrypt(byte[] clearData, PGPPublicKey encKey, boolean withIntegrityCheck, boolean armor) 
    throws IOException, PGPException, NoSuchProviderException {

    ByteArrayOutputStream encOut = new ByteArrayOutputStream();

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

    ByteArrayOutputStream bOut = new ByteArrayOutputStream();

    PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();

    OutputStream pOut = lData.open(bOut/*cos*/, // the compressed output stream
        PGPLiteralData.BINARY, PGPLiteralData.CONSOLE, // "filename" to store (if provided)
        clearData.length, // length of clear data
        new Date() // current time
        );
    pOut.write(clearData);

    PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, withIntegrityCheck, new SecureRandom(), C_BC_PROVIDER_NAME);
    cPk.addMethod(encKey);

    byte[] bytes = bOut.toByteArray();
    bOut.close();

    OutputStream cOut = cPk.open(out, bytes.length);

    cOut.write(bytes); 

    cOut.close();
    out.close();
    return encOut.toByteArray();
} // encrypt
尝试:


您可能正在创建一个分离的签名,并将原始文件与其他实用程序保留在一起。您能否详细说明您的评论?您能否详细说明您的问题?你没有提供任何关于真正区别的例子。我费心第二次看了你的代码,我发现你的代码也有可能输出装甲文本,它的大小大约是二进制数据的两倍。
import org.bouncycastle.openpgp.PGPCompressedDataGenerator;