Class KeyGripCalculator

java.lang.Object
org.bouncycastle.gpg.KeyGripCalculator

public class KeyGripCalculator extends Object
Compute the GnuPG-style "keygrip" for a public key. The keygrip is a 20-byte SHA-1 identifier used by GnuPG 2.x to look up a key without exposing the fingerprint, and is documented in agent/keyformat.txt of the GnuPG source tree.

The supplied PGPDigestCalculator must wrap SHA-1; the keygrip algorithm is fixed by the GnuPG specification.

Currently RSA public keys are supported; the algorithm matches libgcrypt's _gcry_rsa_compute_keygrip (SHA-1 of the canonical unsigned big-endian encoding of the modulus n).

  • Constructor Details

    • KeyGripCalculator

      public KeyGripCalculator(PGPDigestCalculator digestCalculator)
      Parameters:
      digestCalculator - a SHA-1 digest calculator used to compute the keygrip.
  • Method Details

    • calculateKeygrip

      public byte[] calculateKeygrip(BCPGKey key) throws IOException
      Compute the keygrip for the supplied PGP public-key material.
      Parameters:
      key - the BCPGKey to be hashed.
      Returns:
      20 bytes of SHA-1 output.
      Throws:
      IOException - if writing to the digest calculator fails.
      IllegalArgumentException - if no keygrip algorithm is registered for the key type.