Class KeyGrip

java.lang.Object
org.eclipse.jgit.gpg.bc.internal.keys.KeyGrip

public final class KeyGrip extends 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.
  • Field Details

    • OID_OPENPGP_ED25519

      private static String OID_OPENPGP_ED25519
    • OID_RFC8410_CURVE25519

      private static String OID_RFC8410_CURVE25519
    • OID_RFC8410_ED25519

      private static String OID_RFC8410_ED25519
  • Constructor Details

    • KeyGrip

      private KeyGrip()
  • Method Details

    • 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, BigInteger q) throws org.bouncycastle.openpgp.PGPException
      Throws:
      org.bouncycastle.openpgp.PGPException
    • hashEd25519

      static byte[] hashEd25519(SHA1 grip, 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, 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)