Class KeyRingUtils


  • public class KeyRingUtils
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      KeyRingUtils()  
    • 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 primary PGPPublicKey from the provided key ring or null if it has none.
      static org.bouncycastle.openpgp.PGPSecretKey getPrimarySecretKeyFrom​(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys)
      Return the primary PGPSecretKey from the provided PGPSecretKeyRing or null if it has none.
      static org.bouncycastle.openpgp.PGPPublicKey getPublicKeyFrom​(org.bouncycastle.openpgp.PGPKeyRing keyRing, long subKeyId)  
      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 org.bouncycastle.openpgp.PGPPublicKeyRing publicKeyRingFrom​(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys)
      Extract a PGPPublicKeyRing containing all public keys from the provided PGPSecretKeyRing.
      static org.bouncycastle.openpgp.PGPSecretKeyRing removeUnassociatedKeysFromKeyRing​(org.bouncycastle.openpgp.PGPSecretKeyRing ring, org.bouncycastle.openpgp.PGPPublicKey masterKey)
      Remove all keys from the key ring, are either not having a subkey signature from the master key (identified by masterKeyId), or are revoked ("normal" key revocation, as well as subkey revocation).
      static org.bouncycastle.openpgp.PGPPublicKey requirePrimaryPublicKeyFrom​(org.bouncycastle.openpgp.PGPKeyRing keyRing)
      Return the primary PGPPublicKey from the provided key ring.
      static org.bouncycastle.openpgp.PGPSecretKey requirePrimarySecretKeyFrom​(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys)
      Return the primary PGPSecretKey from the provided PGPSecretKeyRing.
      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.PGPPrivateKey unlockSecretKey​(org.bouncycastle.openpgp.PGPSecretKey secretKey, SecretKeyRingProtector protector)
      Unlock a PGPSecretKey and return the resulting PGPPrivateKey.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • KeyRingUtils

        public KeyRingUtils()
    • Method Detail

      • requirePrimarySecretKeyFrom

        public static org.bouncycastle.openpgp.PGPSecretKey requirePrimarySecretKeyFrom​(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys)
        Return the primary PGPSecretKey from the provided PGPSecretKeyRing. If it has no primary secret key, throw a NoSuchElementException.
        Parameters:
        secretKeys - secret keys
        Returns:
        primary secret key
      • getPrimarySecretKeyFrom

        public static org.bouncycastle.openpgp.PGPSecretKey getPrimarySecretKeyFrom​(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys)
        Return the primary PGPSecretKey from the provided PGPSecretKeyRing 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 primary PGPPublicKey from the provided key ring. Throws a NoSuchElementException 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 primary PGPPublicKey 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 a PGPPublicKeyRing containing all public keys from the provided PGPSecretKeyRing.
        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 a PGPSecretKey and return the resulting PGPPrivateKey.
        Parameters:
        secretKey - secret key
        protector - protector to unlock the secret key
        Returns:
        private key
        Throws:
        org.bouncycastle.openpgp.PGPException - if something goes wrong (eg. wrong passphrase)
      • keyRingsToKeyRingCollection

        public static org.bouncycastle.openpgp.PGPPublicKeyRingCollection keyRingsToKeyRingCollection​(@Nonnull
                                                                                                      org.bouncycastle.openpgp.PGPPublicKeyRing... rings)
                                                                                               throws java.io.IOException,
                                                                                                      org.bouncycastle.openpgp.PGPException
        Throws:
        java.io.IOException
        org.bouncycastle.openpgp.PGPException
      • keyRingsToKeyRingCollection

        public static org.bouncycastle.openpgp.PGPSecretKeyRingCollection keyRingsToKeyRingCollection​(@Nonnull
                                                                                                      org.bouncycastle.openpgp.PGPSecretKeyRing... rings)
                                                                                               throws java.io.IOException,
                                                                                                      org.bouncycastle.openpgp.PGPException
        Throws:
        java.io.IOException
        org.bouncycastle.openpgp.PGPException
      • removeUnassociatedKeysFromKeyRing

        public static org.bouncycastle.openpgp.PGPSecretKeyRing removeUnassociatedKeysFromKeyRing​(@Nonnull
                                                                                                  org.bouncycastle.openpgp.PGPSecretKeyRing ring,
                                                                                                  @Nonnull
                                                                                                  org.bouncycastle.openpgp.PGPPublicKey masterKey)
        Remove all keys from the key ring, are either not having a subkey signature from the master key (identified by masterKeyId), or are revoked ("normal" key revocation, as well as subkey revocation).
        Parameters:
        ring - key ring
        masterKey - master key
        Returns:
        "cleaned" key ring
      • keyRingContainsKeyWithId

        public static boolean keyRingContainsKeyWithId​(@Nonnull
                                                       org.bouncycastle.openpgp.PGPPublicKeyRing ring,
                                                       long keyId)