Package google.registry.keyring.api
Class PgpHelper
java.lang.Object
google.registry.keyring.api.PgpHelper
Helper functions for extracting PGP keys from their keyrings.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Narrowed key search requirements. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
convertPublicKeyToBytes
(org.bouncycastle.openpgp.PGPPublicKey publicKey) ConvertspublicKey
to bytes.static boolean
isSigningKey
(org.bouncycastle.openpgp.PGPPublicKey key) Returnstrue
if this key can be used for signing.static org.bouncycastle.openpgp.PGPPublicKey
loadPublicKeyBytes
(byte[] data) Returns raw key bytes as a Bouncy Castle PGP public key.static org.bouncycastle.openpgp.PGPKeyPair
lookupKeyPair
(org.bouncycastle.openpgp.PGPPublicKeyRingCollection publics, org.bouncycastle.openpgp.PGPSecretKeyRingCollection privates, String query, PgpHelper.KeyRequirement want) Same aslookupPublicKey(org.bouncycastle.openpgp.PGPPublicKeyRingCollection, java.lang.String, google.registry.keyring.api.PgpHelper.KeyRequirement)
but also retrieves the associated private key.static org.bouncycastle.openpgp.PGPPublicKey
lookupPublicKey
(org.bouncycastle.openpgp.PGPPublicKeyRingCollection keyring, String query, PgpHelper.KeyRequirement want) Search for public key on keyring based on a substring (like an email address).static Optional
<org.bouncycastle.openpgp.PGPPublicKey> lookupPublicSubkey
(org.bouncycastle.openpgp.PGPPublicKeyRing ring, PgpHelper.KeyRequirement want) Return appropriate key or subkey for given task from public key.
-
Constructor Details
-
PgpHelper
public PgpHelper()
-
-
Method Details
-
convertPublicKeyToBytes
public static byte[] convertPublicKeyToBytes(org.bouncycastle.openpgp.PGPPublicKey publicKey) ConvertspublicKey
to bytes. -
loadPublicKeyBytes
public static org.bouncycastle.openpgp.PGPPublicKey loadPublicKeyBytes(byte[] data) Returns raw key bytes as a Bouncy Castle PGP public key. -
lookupPublicKey
public static org.bouncycastle.openpgp.PGPPublicKey lookupPublicKey(org.bouncycastle.openpgp.PGPPublicKeyRingCollection keyring, String query, PgpHelper.KeyRequirement want) Search for public key on keyring based on a substring (like an email address).- Throws:
com.google.common.base.VerifyException
- if the key couldn't be found.- See Also:
-
lookupKeyPair
public static org.bouncycastle.openpgp.PGPKeyPair lookupKeyPair(org.bouncycastle.openpgp.PGPPublicKeyRingCollection publics, org.bouncycastle.openpgp.PGPSecretKeyRingCollection privates, String query, PgpHelper.KeyRequirement want) Same aslookupPublicKey(org.bouncycastle.openpgp.PGPPublicKeyRingCollection, java.lang.String, google.registry.keyring.api.PgpHelper.KeyRequirement)
but also retrieves the associated private key.- Throws:
com.google.common.base.VerifyException
- if either keys couldn't be found.- See Also:
-
lookupPublicSubkey
public static Optional<org.bouncycastle.openpgp.PGPPublicKey> lookupPublicSubkey(org.bouncycastle.openpgp.PGPPublicKeyRing ring, PgpHelper.KeyRequirement want) Return appropriate key or subkey for given task from public key.Weirder older PGP public keys will actually have multiple keys. The main key will usually be sign-only in such situations. So you've gotta go digging in through the key packets and make sure you get the one that's valid for encryption, or whatever you want to do.
-
isSigningKey
public static boolean isSigningKey(org.bouncycastle.openpgp.PGPPublicKey key) Returnstrue
if this key can be used for signing.
-