2021-10-07 15:48:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
-->
|
|
|
|
|
2021-07-17 00:27:58 +02:00
|
|
|
# PGPainless-SOP
|
|
|
|
|
2022-05-07 22:15:13 +02:00
|
|
|
[![Spec Revision: 3](https://img.shields.io/badge/Spec%20Revision-3-blue)](https://datatracker.ietf.org/doc/draft-dkg-openpgp-stateless-cli/)
|
2022-01-10 16:44:18 +01:00
|
|
|
[![Maven Central](https://badgen.net/maven/v/maven-central/org.pgpainless/pgpainless-sop)](https://search.maven.org/artifact/org.pgpainless/pgpainless-sop)
|
2022-02-11 14:23:19 +01:00
|
|
|
[![javadoc](https://javadoc.io/badge2/org.pgpainless/pgpainless-sop/javadoc.svg)](https://javadoc.io/doc/org.pgpainless/pgpainless-sop)
|
2022-01-10 16:44:18 +01:00
|
|
|
|
2021-07-17 00:27:58 +02:00
|
|
|
Implementation of the Stateless OpenPGP Protocol using PGPainless.
|
|
|
|
|
|
|
|
This module implements `sop-java` using `pgpainless-core`.
|
2022-01-10 16:44:18 +01:00
|
|
|
If your code depends on `sop-java`, this module can be used as a realization of those interfaces.
|
|
|
|
|
2022-01-15 14:38:36 +01:00
|
|
|
## Get started
|
|
|
|
|
|
|
|
To start using pgpainless-sop in your code, include the following lines in your build script:
|
|
|
|
```
|
|
|
|
// If you use Gradle
|
|
|
|
...
|
|
|
|
dependencies {
|
|
|
|
...
|
2022-05-05 11:22:59 +02:00
|
|
|
implementation "org.pgpainless:pgpainless-sop:1.2.2"
|
2022-01-15 14:38:36 +01:00
|
|
|
...
|
|
|
|
}
|
|
|
|
|
|
|
|
// If you use Maven
|
|
|
|
...
|
|
|
|
<dependencies>
|
|
|
|
...
|
|
|
|
<dependency>
|
|
|
|
<groupId>org.pgpainless</groupId>
|
|
|
|
<artifactId>pgpainless-sop</artifactId>
|
2022-05-05 11:22:59 +02:00
|
|
|
<version>1.2.2</version>
|
2022-01-15 14:38:36 +01:00
|
|
|
</dependency>
|
|
|
|
...
|
|
|
|
</dependencies>
|
|
|
|
```
|
|
|
|
|
|
|
|
`pgpainless-sop` will transitively pull in its dependencies, such as `sop-java` and `pgpainless-core`.
|
|
|
|
|
2022-01-10 16:44:18 +01:00
|
|
|
## Usage Examples
|
|
|
|
```java
|
|
|
|
SOP sop = new SOPImpl();
|
|
|
|
|
|
|
|
// Generate an OpenPGP key
|
|
|
|
byte[] key = sop.generateKey()
|
|
|
|
.userId("Alice <alice@example.org>")
|
|
|
|
.generate()
|
|
|
|
.getBytes();
|
|
|
|
|
|
|
|
// Extract the certificate (public key)
|
|
|
|
byte[] cert = sop.extractCert()
|
|
|
|
.key(key)
|
|
|
|
.getBytes();
|
|
|
|
|
|
|
|
// Encrypt a message
|
|
|
|
byte[] message = ...
|
|
|
|
byte[] encrypted = sop.encrypt()
|
|
|
|
.withCert(cert)
|
|
|
|
.signWith(key)
|
|
|
|
.plaintext(message)
|
|
|
|
.getBytes();
|
|
|
|
|
|
|
|
// Decrypt a message
|
|
|
|
ByteArrayAndResult<DecryptionResult> messageAndVerifications = sop.decrypt()
|
|
|
|
.verifyWith(cert)
|
|
|
|
.withKey(key)
|
|
|
|
.ciphertext(encrypted)
|
|
|
|
.toByteArrayAndResult();
|
|
|
|
byte[] decrypted = messageAndVerifications.getBytes();
|
|
|
|
// Signature Verifications
|
|
|
|
DecryptionResult messageInfo = messageAndVerifications.getResult();
|
|
|
|
List<Verification> signatureVerifications = messageInfo.getVerifications();
|
2022-02-25 16:12:56 +01:00
|
|
|
```
|