1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-15 05:09:38 +02:00

Wip: Allow for additional user-ids to be added

This commit is contained in:
Paul Schaub 2020-10-16 12:46:58 +02:00
parent 6a4fa47c12
commit 8c30db9bf1
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 118 additions and 15 deletions

View file

@ -0,0 +1,38 @@
package org.pgpainless.key.generation;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.openpgp.PGPException;
import org.junit.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.key.collection.PGPKeyRing;
import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.RSA_SIGN;
import org.pgpainless.key.generation.type.length.RsaLength;
public class GenerateKeyWithAdditionalUserIdTest {
@Test
public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
PGPKeyRing keyRing = PGPainless.generateKeyRing()
.withMasterKey(KeySpec.getBuilder(RSA_SIGN.withLength(RsaLength._3072))
.withDefaultKeyFlags()
.withDefaultAlgorithms())
.withPrimaryUserId("primary@user.id")
.withAdditionalUserId("additional@user.id")
.withoutPassphrase()
.build();
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ArmoredOutputStream armor = new ArmoredOutputStream(byteOut);
keyRing.getSecretKeys().encode(armor);
armor.close();
System.out.println(byteOut.toString("UTF-8"));
}
}