1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-16 17:32:06 +01:00
pgpainless/README.md

154 lines
6.1 KiB
Markdown
Raw Normal View History

2018-07-24 16:06:45 +02:00
PGPainless - Use OpenPGP Painlessly!
====================================
[![Travis (.com)](https://travis-ci.com/pgpainless/pgpainless.svg?branch=master)](https://travis-ci.com/pgpainless/pgpainless)
2018-07-24 16:06:45 +02:00
[![Git Tag](https://badgen.now.sh/github/tag/pgpainless/pgpainless)](https://github.com/pgpainless/pgpainless/tags)
2018-07-24 16:18:05 +02:00
[![Coverage Status](https://coveralls.io/repos/github/pgpainless/pgpainless/badge.svg?branch=master)](https://coveralls.io/github/pgpainless/pgpainless?branch=master)
2020-08-30 23:06:40 +02:00
[![JavaDoc](https://badgen.net/badge/javadoc/yes/green)](https://pgpainless.org/releases/latest/javadoc/)
2018-07-24 16:06:45 +02:00
About
-----
2018-06-27 16:06:50 +02:00
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
2021-05-06 00:04:03 +02:00
setup of encryptionOptions / decrytion operations, as well as straight forward key generation.
2018-06-27 16:06:50 +02:00
PGPainless is based around the Bouncycastle java library and can be used on Android down to API level 10.
2018-06-27 16:06:50 +02:00
2020-08-30 23:06:40 +02:00
### NOTE: PGPainless is in an early state of development. There may be dragons!
2018-06-27 16:06:50 +02:00
2018-07-19 19:01:16 +02:00
## 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.
2018-07-30 17:58:23 +02:00
```gradle
2018-07-19 19:01:16 +02:00
repositories {
mavenCentral()
}
dependencies {
2020-08-30 23:24:21 +02:00
implementation 'org.pgpainless:pgpainless-core:0.1.0'
2018-07-19 19:01:16 +02:00
}
```
2018-06-27 16:06:50 +02:00
## 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
2018-07-30 17:58:23 +02:00
```java
2021-01-12 15:31:43 +01:00
PGPKeyRing keyRing = PGPainless.generateKeyRing()
2018-06-28 15:49:32 +02:00
.simpleRsaKeyRing("Juliet <juliet@montague.lit>", RsaLength._4096);
2018-06-27 16:06:50 +02:00
```
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:
2018-07-30 17:58:23 +02:00
```java
2018-06-27 16:06:50 +02:00
PGPSecretKeyRing keyRing = PGPainless.generateKeyRing()
.withSubKey(
KeySpec.getBuilder(ECDSA.fromCurve(EllipticCurve._P256))
.withKeyFlags(KeyFlag.SIGN_DATA)
.withDetailedConfiguration()
.withDefaultSymmetricAlgorithms()
.withDefaultHashAlgorithms()
.withPreferredCompressionAlgorithms(CompressionAlgorithm.ZLIB)
.withFeature(Feature.MODIFICATION_DETECTION)
.done())
.withSubKey(
KeySpec.getBuilder(ECDH.fromCurve(EllipticCurve._P256))
.withKeyFlags(KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE)
.withDefaultAlgorithms())
.withMasterKey(
KeySpec.getBuilder(RSA.withLength(RsaLength._8192))
2018-06-27 16:06:50 +02:00
.withKeyFlags(KeyFlag.SIGN_DATA, KeyFlag.CERTIFY_OTHER)
.withDefaultAlgorithms())
.withPrimaryUserId("Juliet <juliet@montague.lit>")
.withPassphrase("romeo_oh_Romeo<3")
.build();
```
### Encrypt / Sign Data
2021-05-06 00:04:03 +02:00
Encrypting and signingOptions data is pretty straight forward as well.
2018-07-30 17:58:23 +02:00
```java
EncryptionStream encryptor = PGPainless.encryptAndOrSign()
2018-06-27 16:06:50 +02:00
.onOutputStream(targetOuputStream)
.toRecipients(publicKeyRings)
.usingSecureAlgorithms()
.signWith(secretKeyDecryptor, signingKeyRing)
.noArmor();
```
2020-08-30 23:06:40 +02:00
Note: Despite the name, the `EncryptionStream` can be used to sign only as well. Simply replace the `.toRecipients()` option with `doNotEncrypt()`.
2018-06-27 16:06:50 +02:00
The resulting `EncryptionStream` can then be used to encrypt data like follows:
2018-07-30 17:58:23 +02:00
```java
2018-06-27 16:06:50 +02:00
Streams.pipeAll(sourceInputStream, encryptor);
sourceInputStream.close();
encryptor.close();
```
The encrypted data will be written to the provided `targetOutputStream`.
Additionally you can get information about the encrypted data by calling
2018-07-30 17:58:23 +02:00
```java
2020-08-30 23:06:40 +02:00
OpenPgpMetadata result = encryptor.getResult();
2018-06-27 16:06:50 +02:00
```
2021-05-06 00:04:03 +02:00
This object will contain information like to which keys the message is encrypted, which keys were used for signingOptions and so on.
2018-06-27 16:06:50 +02:00
### Decrypt / Verify Encrypted Data
To process incoming encrypted / signed data, just do the following:
2018-07-30 17:58:23 +02:00
```java
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
2018-06-27 16:06:50 +02:00
.onInputStream(sourceInputStream) // insert encrypted data here
.decryptWith(secretKeyDecryptor, secretKey)
.verifyWith(trustedKeyIds, senderKeys)
.ignoreMissingPublicKeys()
.build();
```
Again, the resulting `DecryptionStream` can be used like a normal stream.
2018-07-30 17:58:23 +02:00
```java
2018-06-27 16:06:50 +02:00
Streams.pipeAll(decryptor, targetOutputStream);
decryptor.close();
```
2020-08-30 23:06:40 +02:00
*After* the `DecryptionStream` was closed, you can get metadata about the processed data by retrieving the `OpenPgpMetadata`.
2018-06-27 16:06:50 +02:00
Again, this object will contain information about how the message was encrypted, who signed it and so on.
2018-07-30 17:58:23 +02:00
```java
2020-08-30 23:06:40 +02:00
OpenPgpMetadata result = decryptor.getResult();
2018-06-27 16:06:50 +02:00
```
2020-08-30 23:06:40 +02:00
For further details you should check out the [javadoc](https://pgpainless.org/releases/latest/javadoc/)!
2018-06-27 16:06:50 +02:00
## About
PGPainless is a by-product of my [Summer of Code 2018 project](https://blog.jabberhead.tk/summer-of-code-2018/).
2018-06-27 16:06:50 +02:00
For that project I was in need of a simple to use OpenPGP library.
Originally I was going to use [Bouncy-GPG](https://github.com/neuhalje/bouncy-gpg) for my project,
but ultimately I decided to create my own OpenPGP library which better fits my needs.
2020-08-30 23:06:40 +02:00
However, PGPainless is heavily influenced by Bouncy-GPG.
2018-07-18 16:55:48 +02:00
To reach out to the development team, feel free to send a mail: info@pgpainless.org
## Development
PGPainless is developed in - and accepts contributions from - the following places:
* [Github](https://github.com/pgpainless/pgpainless)
* [Codeberg](https://codeberg.org/PGPainless/pgpainless)
2018-07-18 16:55:48 +02:00
Please follow the [code of conduct](CODE_OF_CONDUCT.md) if you want to be part of the project.