Detailed operation steps of Java PGP encryption and decryption example tutorial

This article will tell you the steps to use PGP step by step. After reading it, you can immediately use it in your project and working environment, so easy!!!

1. First understand what is PGP and what is the working principle of PGP? This is directly Baidu Encyclopedia, I will not be verbose.
PGP is the abbreviation of Pretty Good Privacy in English .
Introduction to Baidu Encyclopedia:
http://baike.baidu.com/link?url=5cONqc560BbLi0pFPQZ_shK1IrK_LzkjL8LpS9SW_AtXfDF-OXmBaclSeYv6WSMvnWv9cHWsmsUu5emyg8w39K
 
2. Use of PGP encryption and decryption tools.
Here I introduce a free lightweight PGP tool Portable PGP, the address is as follows:
 https://sourceforge.net/projects/ppgp/
Open is a folder that contains various system startup commands.
44619.tmp
 
 
 
630526.tmp
 
 
Create a key pair (private key, public key): The public key is generally sent to the other party to encrypt files, and the private key is used to decrypt the received files.
1.pic.jpg
2.pic.jpg
3.pic.jpg
4.pic.jpg
 
 
3. Use the created key for file encryption: create a new test.txt document for demonstration.
1.pic.jpg
 
2.pic.jpg
3.pic.jpg
 
4. Decrypt the file: use the encrypted_test.pgp file just encrypted with the public key for decryption demonstration. (Because it was just encrypted with the public key of the key pair, now use the corresponding private key for decryption)
4.pic.jpg
 
1.jpg
 
 
6.pic.jpg
 
 
 
5. The above are the steps of using tools to encrypt and decrypt PGP; next, let's test the encryption and decryption steps based on java. (only the decryption process is demonstrated here)
 Download Bouncy Castle: Bouncy Castle supports a large number of cryptographic algorithms, including OpenPGP, which is widely cited. Pega uses Bouncy Castle to encrypt and decrypt important data of emails and customers.
  bcprov-jdk15on-154.jar, bcpg-jdk15on-154.jar (when you see it, the version may have been updated)
 
 
6. Download UnlimitedJCEPolicy from Oracle official website: JDK default Policy can only support <=128-bit Key, GPG key is from 1024-2048, so this Policy must be extended.
 The downloaded local_policy.jar, US_export_policy.jar two JARs cover the two JARs in the system jre environment; for example: ../jre/lib/security/
 
7. The example code is as follows.
Directory Structure:
9.pic.jpg
 
----- KeyBasedFileProcessor class: ------
For follow-up and more details, please read this article:
 
If you have any questions, please add communication


 
 
 
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326645455&siteId=291194637