Class AbstractOKPJWK<A extends PublicKey,B extends PrivateKey>

Type Parameters:
A - the public key type
B - the private key type
All Implemented Interfaces:
AsymmetricJWK<A,B>, JWK, OKPJWK<A,B>, X509JWK<A,B>
Direct Known Subclasses:
GenericEdECJWK, GenericXECJWK

public abstract class AbstractOKPJWK<A extends PublicKey,B extends PrivateKey> extends AbstractX509JWK<A,B> implements OKPJWK<A,B>

Base Octet Key Pair JSON Web Key implementation.

Since:
1.5
Author:
Jeremy Kuhn
  • Field Details

  • Constructor Details

    • AbstractOKPJWK

      public AbstractOKPJWK(OKPCurve curve, String x)

      Creates an untrusted public OKP JWK with the specified curve and public key value.

      Parameters:
      curve - an elliptic curve
      x - the public key value encoded as Base64URL without padding
    • AbstractOKPJWK

      public AbstractOKPJWK(OKPCurve curve, String x, X509Certificate certificate)

      Creates a public OKP JWK with the specified curve, public key value and certificate.

      The JWK is considered trusted if the specified certificate, which is assumed to be validated, is not null.

      Parameters:
      curve - an elliptic curve
      x - the public key encoded as Base64URL without padding
      certificate - an X.509 certificate
    • AbstractOKPJWK

      public AbstractOKPJWK(OKPCurve curve, String x, String d)

      Creates an untrusted private OKP JWK with the specified curve, public key value and private key value.

      Parameters:
      curve - an elliptic curve
      x - the public key value encoded as Base64URL without padding
      d - the private key value encoded as Base64URL without padding
    • AbstractOKPJWK

      public AbstractOKPJWK(OKPCurve curve, String x, String d, B key, boolean trusted)

      Creates a private OKP JWK with the specified curve, public key value, private key value and private key.

      Parameters:
      curve - an elliptic curve
      x - the public key value encoded as Base64URL without padding
      d - the private key value encoded as Base64URL without padding
      key - a private key
      trusted - true to create a trusted JWK, false otherwise
    • AbstractOKPJWK

      public AbstractOKPJWK(OKPCurve curve, String x, String d, X509Certificate certificate)

      Creates a public OKP JWK with the specified curve, public key value, private key value and certificate.

      The JWK is considered trusted if the specified certificate, which is assumed to be validated, is not null.

      Parameters:
      curve - an elliptic curve
      x - the public key value encoded as Base64URL without padding
      d - the private key value encoded as Base64URL without padding
      certificate - an X.509 certificate
    • AbstractOKPJWK

      public AbstractOKPJWK(OKPCurve curve, String x, String d, B key, X509Certificate certificate, boolean trusted)

      Creates a private OKP JWK with the specified curve, public coordinates, private key value, OKP private key and certificate.

      Parameters:
      curve - an elliptic curve
      x - the public key value encoded as Base64URL without padding
      d - the private key value encoded as Base64URL without padding
      key - a private key
      certificate - an X.509 certificate
      trusted - true to create a trusted JWK, false otherwise
  • Method Details

    • getCurve

      public String getCurve()
      Description copied from interface: OKPJWK

      Returns the JWA Elliptic curve name.

      Specified by:
      getCurve in interface OKPJWK<A extends PublicKey,B extends PrivateKey>
      Returns:
      the Elliptic curve name
    • getPublicKey

      public String getPublicKey()
      Description copied from interface: OKPJWK

      Returns the public key encoded as Base64URL.

      Specified by:
      getPublicKey in interface OKPJWK<A extends PublicKey,B extends PrivateKey>
      Returns:
      the Base64URL encoded public key with no padding.
    • getPrivateKey

      public String getPrivateKey()
      Description copied from interface: OKPJWK

      Returns the private key encoded as Base64URL.

      Specified by:
      getPrivateKey in interface OKPJWK<A extends PublicKey,B extends PrivateKey>
      Returns:
      the Base64URL encoded private key with no padding.
    • toJWKThumbprint

      public String toJWKThumbprint(MessageDigest digest)
      Description copied from interface: JWK

      Generates and returns the JWK thumbprint using the specified digest.

      Specified by:
      toJWKThumbprint in interface JWK
      Parameters:
      digest - the message digest to use
      Returns:
      the JWK thumbprint
    • reverse

      protected static void reverse(byte[] arr)

      Reverses the specified byte array.

      Parameters:
      arr - the byte array to reverse
    • swap

      protected static void swap(byte[] arr, int i, int j)

      Swaps the bytes at positions i and j in the specified byte array.

      Parameters:
      arr - a byte array
      i - an index
      j - an index
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface JWK
      Overrides:
      hashCode in class AbstractX509JWK<A extends PublicKey,B extends PrivateKey>
    • equals

      public boolean equals(Object obj)
      Specified by:
      equals in interface JWK
      Overrides:
      equals in class AbstractX509JWK<A extends PublicKey,B extends PrivateKey>