仅在Java中使用密码解密PGP加密文件 [英] Decrypt PGP encrypted file with passphrase only in Java

查看:481
本文介绍了仅在Java中使用密码解密PGP加密文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要解密的名为 filename.txt.pgp的PGP文件。当我从命令行运行解密时,它仅询问我密码。我使用gpg命令:

I have a PGP file named 'filename.txt.pgp' that I need to decrypt. When I run decryption from command-line it asks me only for the password. I use gpg command:

gpg filename.txt.pgp

密码已足够,我的文件已解密。我可以阅读它的内容。

The password is enough and my file is decrypted. I can read it's content.

现在,我应该用Java创建一个实用程序。经过研究,我发现Bouncy Castle图书馆是我最好的选择。但是我可以找到的所有Java示例都使用我没有的公共/私有密钥文件。

Now, I should create an utility in Java. After research I see that Bouncy Castle library is my best choice. But all the examples in Java I can find use public/private key file which I do not have.

请帮我看看Java中解密PGP文件的示例吗?

Could you please help me with an example in Java that decrypts PGP file using just a password?

谢谢。

推荐答案

看看Bouncy Castle网站的文档部分,他们说 ...看看软件包中的测试程序...,他们不是在开玩笑。

If you look at the documentation section of Bouncy Castle's site, they say to "...look at the test programs in the packages..." and they're not joking.

如果您查看Bouncy Castle的jar文件,您会在 \org.bouncycastle\openpgp\examples\ 目录中有一个名为 PBEFileProcessor 的类文件,该文件将涵盖使用其库时基于密码的加密。

If you look inside the jar file from Bouncy Castle you will see under the \org.bouncycastle\openpgp\examples\ directory a class file called "PBEFileProcessor" that will cover password based encryption when using their library.

这是一个链接到其Github存储库中的同一文件。

Here's a link to the same file in their Github repo.

这篇关于仅在Java中使用密码解密PGP加密文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆