Skip to content

Utility to PGP encrypt and decrypt anything (bytes, file, streams)

Notifications You must be signed in to change notification settings

keith0591/pgp-encryption

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgp-encryption

Utility to encrypt and decrypt anything (bytes, file, streams) with pgp encryption

How to use:

The best way is to look at the test class PgpEncryptionTest. But I have shared some quick snippets below if you are in a hurry

For a detailed explanation of how the utility works go here

Encryption:

First instantiate a PgpEncryptionUtil object like so:

PgpEncryptionUtil pgpEncryptionUtil = PgpEncryptionUtil.builder()
                                      .armor(true)
                                      .compressionAlgorithm(CompressionAlgorithmTags.ZIP)
                                      .symmetricKeyAlgorithm(SymmetricKeyAlgorithmTags.AES_128)
                                      .withIntegrityCheck(true)
                                      .build();                                      

To encrypt bytes call:

byte[] encryptedBytes = pgpEncryptionUtil.encrypt(bytesToEncrypt, publicKey)

To encrypt inputstream call:

InputStream encryptedIn = pgpEncryptionUtil.encrypt(<inputstreamToEncrypt>, lengthOfInputstreamToEncrypt, publicKey);

To encrypt file use:

pgpEncryptionUtil.encrypt(fileOutputstream, fileInputstream, fileLength, publicKey))

Decryption:

First instantiate a PgpDecryptionUtil object like so:

 PgpDecryptionUtil pgpDecryptionUtil = new PgpDecryptionUtil(privateKey, passKey);

To decrypt bytes call:

 byte[] decryptedBytes = pgpDecryptionUtil.decrypt(encryptedBytes);

To decrypt files / inputstreams call:

 pgpDecryptionUtil.decrypt(encryptedIn, fileOutputstream);

About

Utility to PGP encrypt and decrypt anything (bytes, file, streams)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages