mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 10:49:39 +02:00
Update some examples in the README file
This commit is contained in:
parent
4e10c8a030
commit
786836fc07
1 changed files with 18 additions and 16 deletions
34
README.md
34
README.md
|
@ -65,24 +65,23 @@ Reading keys from ASCII armored strings or from binary files is easy:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
String key = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n"...
|
String key = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n"...
|
||||||
PGPSecretKeyRing secretKey = PGPainless.readKeyRing()
|
OpenPGPKey secretKey = PGPainless.getInstance().readKey()
|
||||||
.secretKeyRing(key);
|
.parseKey(key);
|
||||||
```
|
```
|
||||||
|
|
||||||
Similarly, keys can quickly be exported::
|
Similarly, keys can quickly be exported::
|
||||||
|
|
||||||
```java
|
```java
|
||||||
PGPSecretKeyRing secretKey = ...;
|
OpenPGPKey secretKey = ...;
|
||||||
String armored = PGPainless.asciiArmor(secretKey);
|
String armored = secretKey.toAsciiArmoredString();
|
||||||
ByteArrayOutputStream binary = new ByteArrayOutputStream();
|
byte[] binary = secretKey.getEncoded();
|
||||||
secretKey.encode(binary);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Extract a public key certificate from a secret key:
|
Extract a public key certificate from a secret key:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
PGPSecretKeyRing secretKey = ...;
|
OpenPGPKey secretKey = ...;
|
||||||
PGPPublicKeyRing certificate = PGPainless.extractCertificate(secretKey);
|
OpenPGPCertificate certificate = secretKey.toCertificate();
|
||||||
```
|
```
|
||||||
|
|
||||||
### Easily Generate Keys
|
### Easily Generate Keys
|
||||||
|
@ -90,16 +89,17 @@ PGPainless comes with a simple to use `KeyRingBuilder` class that helps you to q
|
||||||
There are some predefined key archetypes, but it is possible to fully customize key generation to your needs.
|
There are some predefined key archetypes, but it is possible to fully customize key generation to your needs.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
PGPainless api = PGPainless.getInstance();
|
||||||
// RSA key without additional subkeys
|
// RSA key without additional subkeys
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
OpenPGPKey secretKeys = api.generateKey()
|
||||||
.simpleRsaKeyRing("Juliet <juliet@montague.lit>", RsaLength._4096);
|
.simpleRsaKeyRing("Juliet <juliet@montague.lit>", RsaLength._4096);
|
||||||
|
|
||||||
// EdDSA primary key with EdDSA signing- and XDH encryption subkeys
|
// EdDSA primary key with EdDSA signing- and XDH encryption subkeys
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
OpenPGPKey secretKeys = api.generateKey()
|
||||||
.modernKeyRing("Romeo <romeo@montague.lit>", "I defy you, stars!");
|
.modernKeyRing("Romeo <romeo@montague.lit>", "I defy you, stars!");
|
||||||
|
|
||||||
// Customized key
|
// Customized key
|
||||||
PGPSecretKeyRing keyRing = PGPainless.buildKeyRing()
|
OpenPGPKey keyRing = PGPainless.buildKeyRing()
|
||||||
.setPrimaryKey(KeySpec.getBuilder(
|
.setPrimaryKey(KeySpec.getBuilder(
|
||||||
RSA.withLength(RsaLength._8192),
|
RSA.withLength(RsaLength._8192),
|
||||||
KeyFlag.SIGN_DATA, KeyFlag.CERTIFY_OTHER))
|
KeyFlag.SIGN_DATA, KeyFlag.CERTIFY_OTHER))
|
||||||
|
@ -124,24 +124,26 @@ algorithms accordingly.
|
||||||
Still it allows you to manually specify which algorithms to use of course.
|
Still it allows you to manually specify which algorithms to use of course.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign()
|
PGPainless api = PGPainless.getInstance();
|
||||||
|
EncryptionStream encryptionStream = api.generateMessage()
|
||||||
.onOutputStream(outputStream)
|
.onOutputStream(outputStream)
|
||||||
.withOptions(
|
.withOptions(
|
||||||
ProducerOptions.signAndEncrypt(
|
ProducerOptions.signAndEncrypt(
|
||||||
new EncryptionOptions()
|
EncryptionOptions.get(api)
|
||||||
.addRecipient(aliceKey)
|
.addRecipient(aliceKey)
|
||||||
.addRecipient(bobsKey)
|
.addRecipient(bobsKey)
|
||||||
// optionally encrypt to a passphrase
|
// optionally encrypt to a passphrase
|
||||||
.addMessagePassphrase(Passphrase.fromPassword("password123"))
|
.addMessagePassphrase(Passphrase.fromPassword("password123"))
|
||||||
// optionally override symmetric encryption algorithm
|
// optionally override symmetric encryption algorithm
|
||||||
.overrideEncryptionAlgorithm(SymmetricKeyAlgorithm.AES_192),
|
.overrideEncryptionAlgorithm(SymmetricKeyAlgorithm.AES_192),
|
||||||
new SigningOptions()
|
SigningOptions.get(api)
|
||||||
// Sign in-line (using one-pass-signature packet)
|
// Sign in-line (using one-pass-signature packet)
|
||||||
.addInlineSignature(secretKeyDecryptor, aliceSecKey, signatureType)
|
.addInlineSignature(secretKeyDecryptor, aliceSecKey, signatureType)
|
||||||
// Sign using a detached signature
|
// Sign using a detached signature
|
||||||
.addDetachedSignature(secretKeyDecryptor, aliceSecKey, signatureType)
|
.addDetachedSignature(secretKeyDecryptor, aliceSecKey, signatureType)
|
||||||
// optionally override hash algorithm
|
// optionally override hash algorithm
|
||||||
.overrideHashAlgorithm(HashAlgorithm.SHA256)
|
.overrideHashAlgorithm(HashAlgorithm.SHA256),
|
||||||
|
api
|
||||||
).setAsciiArmor(true) // Ascii armor or not
|
).setAsciiArmor(true) // Ascii armor or not
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -163,7 +165,7 @@ This behaviour can be modified though using the `Policy` class.
|
||||||
```java
|
```java
|
||||||
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
|
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
|
||||||
.onInputStream(encryptedInputStream)
|
.onInputStream(encryptedInputStream)
|
||||||
.withOptions(new ConsumerOptions()
|
.withOptions(ConsumerOptions.get(api)
|
||||||
.addDecryptionKey(bobSecKeys, secretKeyProtector)
|
.addDecryptionKey(bobSecKeys, secretKeyProtector)
|
||||||
.addVerificationCert(alicePubKeys)
|
.addVerificationCert(alicePubKeys)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue