Top Description Constructors Methods
org.eclipse.jgit.gpg.bc.internal.keys

public final Class KeyGrip

extends Object
Class Inheritance
Imports
java.math.BigInteger, java.nio.charset.StandardCharsets, java.text.MessageFormat, java.util.Arrays, org.bouncycastle.asn1.ASN1ObjectIdentifier, org.bouncycastle.asn1.x9.ECNamedCurveTable, .X9ECParameters, org.bouncycastle.bcpg.DSAPublicBCPGKey, .ECPublicBCPGKey, .ElGamalPublicBCPGKey, .PublicKeyAlgorithmTags, .RSAPublicBCPGKey, org.bouncycastle.crypto.ec.CustomNamedCurves, org.bouncycastle.math.ec.ECAlgorithms, org.bouncycastle.math.field.FiniteField, org.bouncycastle.openpgp.PGPException, .PGPPublicKey, org.bouncycastle.util.encoders.Hex, org.eclipse.jgit.annotations.NonNull, org.eclipse.jgit.gpg.bc.internal.BCText, org.eclipse.jgit.util.sha1.SHA1

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

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static byte[]

Returns:

the keygrip
getKeyGrip
(PGPPublicKey
to get the keygrip of
publicKey
)

Computes the keygrip for a PGPPublicKey.

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

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

pack-priv static byte[]

Returns:

the keygrip
hashCurve25519
(SHA1
initialized SHA1
grip
,
BigInteger
the public key's EC point
q
)

Computes the keygrip for a curve25519 public key.

pack-priv static byte[]

Returns:

the keygrip
hashEd25519
(SHA1
initialized SHA1
grip
,
BigInteger
the public key's EC point
q
)

Computes the keygrip for an ed25519 public key.

private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

KeyGripback to summary
private KeyGrip()

Method Detail

getKeyGripback to summary
public static byte[] getKeyGrip(PGPPublicKey publicKey) throws PGPException

Computes the keygrip for a PGPPublicKey.

Parameters
publicKey:PGPPublicKey

to get the keygrip of

Returns:byte[]

the keygrip

Annotations
@NonNull
Exceptions
PGPException:
if an unknown key type is encountered.
getX9Parametersback to summary
private static X9ECParameters getX9Parameters(ASN1ObjectIdentifier curveOID)
hashback to summary
private static void hash(SHA1 grip, byte[] data)
hashback to summary
private static void hash(SHA1 grip, byte[] data, char id, boolean zeroPad)
hashCurve25519back to summary
pack-priv static byte[] hashCurve25519(SHA1 grip, BigInteger q) throws PGPException

Computes the keygrip for a curve25519 public key.

Package-visible for tests only.

Parameters
grip:SHA1

initialized SHA1

q:BigInteger

the public key's EC point

Returns:byte[]

the keygrip

Annotations
@SuppressWarnings:nls
Exceptions
PGPException:
if q indicates uncompressed format
hashEd25519back to summary
pack-priv static byte[] hashEd25519(SHA1 grip, BigInteger q) throws PGPException

Computes the keygrip for an ed25519 public key.

Package-visible for tests only.

Parameters
grip:SHA1

initialized SHA1

q:BigInteger

the public key's EC point

Returns:byte[]

the keygrip

Annotations
@SuppressWarnings:nls
Exceptions
PGPException:
if q indicates uncompressed format
hashQ25519back to summary
private static void hashQ25519(SHA1 grip, BigInteger q) throws PGPException