Skip to content

Latest commit

 

History

History
85 lines (62 loc) · 2.61 KB

README.md

File metadata and controls

85 lines (62 loc) · 2.61 KB

Using JPGPJ Java GPG Library

Refer to JPGPJ for more details.

Requirements:

Assumptions:

  • Sender - Alice ([email protected], passphrase for the secret key = "AlicePassword123")
  • Recipient - Bob ([email protected], passphrase for the secret key = "BobPassword123")
  • Keys:
   ../keys/alice-secret-key.asc    - Alice private key
   ../keys/alice-public-key.asc    - Alice public key
   ../keys/bob-secret-key.asc      - Bob private key
   ../keys/bob-public-key.asc      - Bob public key

Steps:

  • build
  • sign and encrypt the message from Alice to Bob
  • decrypt and verify the encrypted message

Commands:

list keys

$ ls ../keys
alice-public-key.asc  alice-secret-key.asc  bob-public-key.asc  bob-secret-key.asc
$

compile

mvn compile

$ mvn compile -q
$

sign and encrypt the message from Alice to Bob

mvn exec:java -Dexec.mainClass="com.example.EncryptAndSign" -q

$ cat ../message-alice-to-bob.txt
Message from Alice to Bob...
$

$ mvn exec:java -Dexec.mainClass="com.example.EncryptAndSign" -q
16:56:24.761 [com.example.EncryptAndSign.main()] INFO org.c02e.jpgpj.Encryptor - using encryption key sec+ed FB322F6B
16:56:24.791 [com.example.EncryptAndSign.main()] INFO org.c02e.jpgpj.Encryptor - using encryption key pub e  F8DF4D46
16:56:25.346 [com.example.EncryptAndSign.main()] INFO org.c02e.jpgpj.Encryptor - using signing key sec+vs 557D725A Alice <[email protected]>
16:56:25.415 [com.example.EncryptAndSign.main()] DEBUG org.c02e.jpgpj.Encryptor - using signing uid Alice <[email protected]>
$

$ ls ../message-alice-to-bob.txt.gpg
../message-alice-to-bob.txt.gpg
$

decrypt and verify the encrypted message

mvn exec:java -Dexec.mainClass="com.example.DecryptAndVerify" -q

$ mvn exec:java -Dexec.mainClass="com.example.DecryptAndVerify" -q
16:59:36.622 [com.example.DecryptAndVerify.main()] INFO org.c02e.jpgpj.Decryptor - not using decryption key pub e  FB322F6B
16:59:36.627 [com.example.DecryptAndVerify.main()] INFO org.c02e.jpgpj.Decryptor - using decryption key sec+ed F8DF4D46
16:59:37.189 [com.example.DecryptAndVerify.main()] INFO org.c02e.jpgpj.Decryptor - using verification key pub v  557D725A Alice <[email protected]>
16:59:37.228 [com.example.DecryptAndVerify.main()] DEBUG org.c02e.jpgpj.Decryptor - good signature for key pub v  557D725A Alice <[email protected]>
pub e  FB322F6B
$

$ cat ../message-alice-to-bob-decrypted.txt
Message from Alice to Bob...
$