我已经获得了能够加载公钥的代码,并使用其他人提供的公钥加密byte []数组。但是,当我解密文件时,它没有.csv扩展名。我可以在Excel中打开它,一旦打开它就看起来像csv,但文件没有任何与之关联的扩展名,所以我不得不在Excel中奇怪地打开它。
我还附上了我的代码,我无法弄清楚在哪里修改它,以便当我使用Kleopatra解密它时,它会以.csv扩展名显示。我试图将输出流从.gpg文件更改为.csv,但随后它会抛出一个错误,说它无法确定这是否是OpenPGP签名。我想我必须对lData.open()方法做一些事情,但我可以放在那里的唯一选项是PGPLiteralData.TEXT,BINARY和UTF8。也许这与在文件中添加签名有关吗?
顺便说一句,对于下面的代码,公钥已经加载到名为pubkey的变量中。
byte[] bytesArray = getAccessChannels(customerAlias);
OutputStream out = new FileOutputStream("/path/to/file/eData.gpg");
Security.addProvider(new BouncyCastleProvider());
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(PGPCompressedDataGenerator.ZIP);
OutputStream cos = comData.open(bOut); // open it with the final destination
PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();
OutputStream pOut = lData.open(cos, PGPLiteralData.TEXT, "Report.csv", bytesArray.length, new Date());
pOut.write(bytesArray);
lData.close();
comData.close();
PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(new BcPGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.AES_256).setSecureRandom(new SecureRandom()));
cPk.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(pubKey));
byte[] bytes = bOut.toByteArray();
OutputStream cOut = cPk.open(out, bytes.length);
cOut.write(bytes); // obtain the actual bytes from the compressed stream
cOut.close();
答案 0 :(得分:0)
没关系,我只需要将文件扩展名更改为eData.csv.gpg ...这花了我整整2天