Class KeyGrip


  • public final class KeyGrip
    extends java.lang.Object
    Utilities to compute the keygrip of a key. A keygrip is a SHA1 hash over the public key parameters and is used internally by the gpg-agent to find the secret key belonging to a public key: the secret key is stored in a file under ~/.gnupg/private-keys-v1.d/ with a name "<keygrip>.key". While this storage organization is an implementation detail of GPG, the way keygrips are computed is not; they are computed by libgcrypt and their definition is stable.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private KeyGrip()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] getKeyGrip​(org.bouncycastle.openpgp.PGPPublicKey publicKey)
      Computes the keygrip for a PGPPublicKey.
      private static org.bouncycastle.asn1.x9.X9ECParameters getX9Parameters​(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOID)  
      private static void hash​(SHA1 grip, byte[] data)  
      private static void hash​(SHA1 grip, byte[] data, char id, boolean zeroPad)  
      (package private) static byte[] hashCurve25519​(SHA1 grip, java.math.BigInteger q)
      Computes the keygrip for a curve25519 public key.
      (package private) static byte[] hashEd25519​(SHA1 grip, java.math.BigInteger q)
      Computes the keygrip for an ed25519 public key.
      private static void hashQ25519​(SHA1 grip, java.math.BigInteger q)  
      • Methods inherited from class java.lang.Object

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

      • OID_OPENPGP_ED25519

        private static java.lang.String OID_OPENPGP_ED25519
      • OID_RFC8410_CURVE25519

        private static java.lang.String OID_RFC8410_CURVE25519
      • OID_RFC8410_ED25519

        private static java.lang.String OID_RFC8410_ED25519
      • CURVE25519

        private static org.bouncycastle.asn1.ASN1ObjectIdentifier CURVE25519
    • Constructor Detail

      • KeyGrip

        private KeyGrip()
    • Method Detail

      • getKeyGrip

        @NonNull
        public static byte[] getKeyGrip​(org.bouncycastle.openpgp.PGPPublicKey publicKey)
                                 throws org.bouncycastle.openpgp.PGPException
        Computes the keygrip for a PGPPublicKey.
        Parameters:
        publicKey - to get the keygrip of
        Returns:
        the keygrip
        Throws:
        org.bouncycastle.openpgp.PGPException - if an unknown key type is encountered.
      • hash

        private static void hash​(SHA1 grip,
                                 byte[] data)
      • hash

        private static void hash​(SHA1 grip,
                                 byte[] data,
                                 char id,
                                 boolean zeroPad)
      • hashQ25519

        private static void hashQ25519​(SHA1 grip,
                                       java.math.BigInteger q)
                                throws org.bouncycastle.openpgp.PGPException
        Throws:
        org.bouncycastle.openpgp.PGPException
      • hashEd25519

        static byte[] hashEd25519​(SHA1 grip,
                                  java.math.BigInteger q)
                           throws org.bouncycastle.openpgp.PGPException
        Computes the keygrip for an ed25519 public key.

        Package-visible for tests only.

        Parameters:
        grip - initialized SHA1
        q - the public key's EC point
        Returns:
        the keygrip
        Throws:
        org.bouncycastle.openpgp.PGPException - if q indicates uncompressed format
      • hashCurve25519

        static byte[] hashCurve25519​(SHA1 grip,
                                     java.math.BigInteger q)
                              throws org.bouncycastle.openpgp.PGPException
        Computes the keygrip for a curve25519 public key.

        Package-visible for tests only.

        Parameters:
        grip - initialized SHA1
        q - the public key's EC point
        Returns:
        the keygrip
        Throws:
        org.bouncycastle.openpgp.PGPException - if q indicates uncompressed format
      • getX9Parameters

        private static org.bouncycastle.asn1.x9.X9ECParameters getX9Parameters​(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOID)