Package org.pgpainless.key.util
Class KeyRingUtils
- java.lang.Object
-
- org.pgpainless.key.util.KeyRingUtils
-
public final class KeyRingUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.bouncycastle.openpgp.PGPPublicKey
getPrimaryPublicKeyFrom(org.bouncycastle.openpgp.PGPKeyRing keyRing)
Return the primaryPGPPublicKey
from the provided key ring or null if it has none.static org.bouncycastle.openpgp.PGPSecretKey
getPrimarySecretKeyFrom(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys)
Return the primaryPGPSecretKey
from the providedPGPSecretKeyRing
or null if it has none.static org.bouncycastle.openpgp.PGPPublicKey
getPublicKeyFrom(org.bouncycastle.openpgp.PGPKeyRing keyRing, long subKeyId)
static <T extends org.bouncycastle.openpgp.PGPKeyRing>
TinjectCertification(T keyRing, String userId, org.bouncycastle.openpgp.PGPSignature certification)
static <T extends org.bouncycastle.openpgp.PGPKeyRing>
TinjectCertification(T keyRing, org.bouncycastle.openpgp.PGPPublicKey certifiedKey, org.bouncycastle.openpgp.PGPSignature certification)
static <T extends org.bouncycastle.openpgp.PGPKeyRing>
TinjectCertification(T keyRing, org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector userAttributes, org.bouncycastle.openpgp.PGPSignature certification)
static boolean
keyRingContainsKeyWithId(org.bouncycastle.openpgp.PGPPublicKeyRing ring, long keyId)
static org.bouncycastle.openpgp.PGPPublicKeyRingCollection
keyRingsToKeyRingCollection(org.bouncycastle.openpgp.PGPPublicKeyRing... rings)
static org.bouncycastle.openpgp.PGPSecretKeyRingCollection
keyRingsToKeyRingCollection(org.bouncycastle.openpgp.PGPSecretKeyRing... rings)
static <T extends org.bouncycastle.openpgp.PGPKeyRing>
TkeysPlusPublicKey(T keyRing, org.bouncycastle.openpgp.PGPPublicKey publicKey)
static org.bouncycastle.openpgp.PGPSecretKeyRing
keysPlusSecretKey(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys, org.bouncycastle.openpgp.PGPSecretKey secretKey)
static org.bouncycastle.openpgp.PGPPublicKeyRing
publicKeyRingFrom(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys)
Extract aPGPPublicKeyRing
containing all public keys from the providedPGPSecretKeyRing
.static org.bouncycastle.openpgp.PGPPublicKey
requirePrimaryPublicKeyFrom(org.bouncycastle.openpgp.PGPKeyRing keyRing)
Return the primaryPGPPublicKey
from the provided key ring.static org.bouncycastle.openpgp.PGPSecretKey
requirePrimarySecretKeyFrom(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys)
Return the primaryPGPSecretKey
from the providedPGPSecretKeyRing
.static org.bouncycastle.openpgp.PGPPublicKey
requirePublicKeyFrom(org.bouncycastle.openpgp.PGPKeyRing keyRing, long subKeyId)
static org.bouncycastle.openpgp.PGPSecretKey
requireSecretKeyFrom(org.bouncycastle.openpgp.PGPSecretKeyRing keyRing, long subKeyId)
static org.bouncycastle.openpgp.PGPSecretKey
secretKeyPlusSignature(org.bouncycastle.openpgp.PGPSecretKey secretKey, org.bouncycastle.openpgp.PGPSignature signature)
static org.bouncycastle.openpgp.PGPPrivateKey
unlockSecretKey(org.bouncycastle.openpgp.PGPSecretKey secretKey, SecretKeyRingProtector protector)
Unlock aPGPSecretKey
and return the resultingPGPPrivateKey
.
-
-
-
Method Detail
-
requirePrimarySecretKeyFrom
public static org.bouncycastle.openpgp.PGPSecretKey requirePrimarySecretKeyFrom(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys)
Return the primaryPGPSecretKey
from the providedPGPSecretKeyRing
. If it has no primary secret key, throw aNoSuchElementException
.- Parameters:
secretKeys
- secret keys- Returns:
- primary secret key
-
getPrimarySecretKeyFrom
public static org.bouncycastle.openpgp.PGPSecretKey getPrimarySecretKeyFrom(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys)
Return the primaryPGPSecretKey
from the providedPGPSecretKeyRing
or null if it has none.- Parameters:
secretKeys
- secret key ring- Returns:
- primary secret key
-
requirePrimaryPublicKeyFrom
public static org.bouncycastle.openpgp.PGPPublicKey requirePrimaryPublicKeyFrom(org.bouncycastle.openpgp.PGPKeyRing keyRing)
Return the primaryPGPPublicKey
from the provided key ring. Throws aNoSuchElementException
if the key ring has no primary public key.- Parameters:
keyRing
- key ring- Returns:
- primary public key
-
getPrimaryPublicKeyFrom
public static org.bouncycastle.openpgp.PGPPublicKey getPrimaryPublicKeyFrom(org.bouncycastle.openpgp.PGPKeyRing keyRing)
Return the primaryPGPPublicKey
from the provided key ring or null if it has none.- Parameters:
keyRing
- key ring- Returns:
- primary public key
-
getPublicKeyFrom
public static org.bouncycastle.openpgp.PGPPublicKey getPublicKeyFrom(org.bouncycastle.openpgp.PGPKeyRing keyRing, long subKeyId)
-
requirePublicKeyFrom
public static org.bouncycastle.openpgp.PGPPublicKey requirePublicKeyFrom(org.bouncycastle.openpgp.PGPKeyRing keyRing, long subKeyId)
-
requireSecretKeyFrom
public static org.bouncycastle.openpgp.PGPSecretKey requireSecretKeyFrom(org.bouncycastle.openpgp.PGPSecretKeyRing keyRing, long subKeyId)
-
publicKeyRingFrom
public static org.bouncycastle.openpgp.PGPPublicKeyRing publicKeyRingFrom(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys)
Extract aPGPPublicKeyRing
containing all public keys from the providedPGPSecretKeyRing
.- Parameters:
secretKeys
- secret key ring- Returns:
- public key ring
-
unlockSecretKey
public static org.bouncycastle.openpgp.PGPPrivateKey unlockSecretKey(org.bouncycastle.openpgp.PGPSecretKey secretKey, SecretKeyRingProtector protector) throws org.bouncycastle.openpgp.PGPException
Unlock aPGPSecretKey
and return the resultingPGPPrivateKey
.- Parameters:
secretKey
- secret keyprotector
- protector to unlock the secret key- Returns:
- private key
- Throws:
org.bouncycastle.openpgp.PGPException
- if something goes wrong (e.g. wrong passphrase)
-
keyRingsToKeyRingCollection
public static org.bouncycastle.openpgp.PGPPublicKeyRingCollection keyRingsToKeyRingCollection(@Nonnull org.bouncycastle.openpgp.PGPPublicKeyRing... rings) throws IOException, org.bouncycastle.openpgp.PGPException
- Throws:
IOException
org.bouncycastle.openpgp.PGPException
-
keyRingsToKeyRingCollection
public static org.bouncycastle.openpgp.PGPSecretKeyRingCollection keyRingsToKeyRingCollection(@Nonnull org.bouncycastle.openpgp.PGPSecretKeyRing... rings) throws IOException, org.bouncycastle.openpgp.PGPException
- Throws:
IOException
org.bouncycastle.openpgp.PGPException
-
keyRingContainsKeyWithId
public static boolean keyRingContainsKeyWithId(@Nonnull org.bouncycastle.openpgp.PGPPublicKeyRing ring, long keyId)
-
injectCertification
public static <T extends org.bouncycastle.openpgp.PGPKeyRing> T injectCertification(T keyRing, org.bouncycastle.openpgp.PGPPublicKey certifiedKey, org.bouncycastle.openpgp.PGPSignature certification)
-
injectCertification
public static <T extends org.bouncycastle.openpgp.PGPKeyRing> T injectCertification(T keyRing, String userId, org.bouncycastle.openpgp.PGPSignature certification)
-
injectCertification
public static <T extends org.bouncycastle.openpgp.PGPKeyRing> T injectCertification(T keyRing, org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector userAttributes, org.bouncycastle.openpgp.PGPSignature certification)
-
keysPlusPublicKey
public static <T extends org.bouncycastle.openpgp.PGPKeyRing> T keysPlusPublicKey(T keyRing, org.bouncycastle.openpgp.PGPPublicKey publicKey)
-
keysPlusSecretKey
public static org.bouncycastle.openpgp.PGPSecretKeyRing keysPlusSecretKey(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys, org.bouncycastle.openpgp.PGPSecretKey secretKey)
-
secretKeyPlusSignature
public static org.bouncycastle.openpgp.PGPSecretKey secretKeyPlusSignature(org.bouncycastle.openpgp.PGPSecretKey secretKey, org.bouncycastle.openpgp.PGPSignature signature)
-
-