簡體   English   中英

使用Bouncy Castle(在Java中)和GPG4Win加密時,文件大小不同

[英]Different file size when encrypting with Bouncy Castle (In Java) and GPG4Win

這是問題所在:我使用Bouncy Castle(Java)庫對文件進行加密,但是與使用其他實用程序(即GPG4Win,FileAssurity)相比,我獲得的加密文件的大小要大得多。 與我的代碼生成的文件相比,這些實用程序生成的加密文件大小很小。

我想知道使用RSA公鑰而不是DSA時是否有不同的加密方式。

附加信息:

公鑰證書類型:2,047位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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM