Simple to use OpenPGP API based on Bouncycastle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Paul Schaub 5cfd7f946a
Add .editorconfig file
6 hours ago
assets/test_vectors Add signed message of cryptie as test vector 1 year ago
config/checkstyle Bump checkstyle to 8.18 1 year ago
gradle/wrapper Bump gradle wrapper to 6.4rc1 8 months ago
pgpainless-core Modified Passphrase.fromPassword() to fit Kotlin needs (#101) 2 days ago
pgpainless-sop Improve error handling in sop tests 1 month ago
.editorconfig Add .editorconfig file 6 hours ago
.gitignore Add bin/ to gitignore 2 years ago
.travis.yml Bump Android SDK level to 10 2 months ago Add code of conduct 3 years ago
LICENSE Add license 3 years ago Fix readme by bumping Android API level 2 months ago
build.gradle Sop: Sync version with gradle version variable and fix format 1 month ago
gradlew Bump gradle wrapper to 6.4rc1 8 months ago
gradlew.bat Bump gradle wrapper to 6.4rc1 8 months ago
settings.gradle Wip: Start implementing a SOP client 4 months ago
version.gradle PGPainless 0.2.0-alpha9-SNAPSHOT 2 months ago

PGPainless - Use OpenPGP Painlessly!

Travis (.com) Git Tag Coverage Status JavaDoc


PGPainless aims to make using OpenPGP in Java projects as simple as possible. It does so by introducing an intuitive Builder structure, which allows easy setup of encryption / decrytion operations, as well as straight forward key generation.

PGPainless is based around the Bouncycastle java library and can be used on Android down to API level 10.

NOTE: PGPainless is in an early state of development. There may be dragons!

Include PGPainless in your Project

PGPainless is available on maven central. In order to include it in your project, just add the maven central repository and add PGPainless as a dependency.

repositories {

dependencies {
	implementation 'org.pgpainless:pgpainless-core:0.1.0'

How to use PGPainless

The entry point to the API is the PGPainless class. Here you can find methods for a quick start :)

Generate Keys

The first thing you probably want to do is generate you some nice tasty Key Pairs. The most straight forward way to do so is by calling

        PGPKeyRing keyRing = PGPainless.generateKeyRing()
                .simpleRsaKeyRing("Juliet <juliet@montague.lit>", RsaLength._4096);

but feel free to explore the API further. PGPainless allows you to create Key Pairs consisting of a master key plus several sub keys, even with different algorithms at the same time! Take for example a look at this delicious key:

        PGPSecretKeyRing keyRing = PGPainless.generateKeyRing()
                        .withKeyFlags(KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE)
                                .withKeyFlags(KeyFlag.SIGN_DATA, KeyFlag.CERTIFY_OTHER)
                .withPrimaryUserId("Juliet <juliet@montague.lit>")

Encrypt / Sign Data

Encrypting and signing data is pretty straight forward as well.

        EncryptionStream encryptor = PGPainless.encryptAndOrSign()
                .signWith(secretKeyDecryptor, signingKeyRing)

Note: Despite the name, the EncryptionStream can be used to sign only as well. Simply replace the .toRecipients() option with doNotEncrypt().

The resulting EncryptionStream can then be used to encrypt data like follows:

        Streams.pipeAll(sourceInputStream, encryptor);

The encrypted data will be written to the provided targetOutputStream.

Additionally you can get information about the encrypted data by calling

        OpenPgpMetadata result = encryptor.getResult();

This object will contain information like to which keys the message is encrypted, which keys were used for signing and so on.

Decrypt / Verify Encrypted Data

To process incoming encrypted / signed data, just do the following:

        DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
                .onInputStream(sourceInputStream) // insert encrypted data here
                .decryptWith(secretKeyDecryptor, secretKey)
                .verifyWith(trustedKeyIds, senderKeys)

Again, the resulting DecryptionStream can be used like a normal stream.

        Streams.pipeAll(decryptor, targetOutputStream);

After the DecryptionStream was closed, you can get metadata about the processed data by retrieving the OpenPgpMetadata. Again, this object will contain information about how the message was encrypted, who signed it and so on.

        OpenPgpMetadata result = decryptor.getResult();

For further details you should check out the javadoc!


PGPainless is a by-product of my Summer of Code 2018 project. For that project I was in need of a simple to use OpenPGP library.

Originally I was going to use Bouncy-GPG for my project, but ultimately I decided to create my own OpenPGP library which better fits my needs.

However, PGPainless is heavily influenced by Bouncy-GPG.

To reach out to the development team, feel free to send a mail:


PGPainless is developed in - and accepts contributions from - the following places:

Please follow the code of conduct if you want to be part of the project.