Class COSEVerifier

java.lang.Object
com.authlete.cose.COSEVerifier

public class COSEVerifier extends Object
A verifier for COSE.
Since:
1.1
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    A constructor with a key getter that is called later when verification is performed.
    A constructor with a public key for verification.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Verify a COSE_Sign object.
    boolean
    Verify a COSE_Sign1 object.
    boolean
    verify(COSESign1 sign1, byte[] externalData)
    Verify a COSE_Sign1 object.
    boolean
    verify(COSESign sign, byte[] externalData)
    Verify a COSE_Sign object.
    boolean
    verify(COSESign sign, COSESignature signature)
    Verify a combination of COSE_Sign and COSE_Signature.
    boolean
    verify(COSESign sign, COSESignature signature, byte[] externalData)
    Verify a combination of COSE_Sign and COSE_Signature.
    static boolean
    verify(Key key, int alg, byte[] data, byte[] signature)
    Verify the signature for the data with the key and the algorithm.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • COSEVerifier

      public COSEVerifier(Key key)
      A constructor with a public key for verification.
      Parameters:
      key - A public key for verification. Must not be null.
    • COSEVerifier

      public COSEVerifier(KeyGetter keyGetter)
      A constructor with a key getter that is called later when verification is performed.

      When verification is performed, the get method of the key getter is called with the first argument COSEKeyOperations.VERIFY.

      Parameters:
      keyGetter - A key getter that returns a public key for verification. Must not be null.
  • Method Details

    • verify

      public boolean verify(COSESign sign) throws COSEException
      Verify a COSE_Sign object.

      This method is an alias of verify(sign, (byte[])null).

      Parameters:
      sign - A COSE_Sign object to verify.
      Returns:
      true if any of signatures in the COSE_Sign object is valid. false if none of signatures in the COSE_Sign object are valid.
      Throws:
      COSEException
    • verify

      public boolean verify(COSESign sign, byte[] externalData) throws COSEException
      Verify a COSE_Sign object.
      Parameters:
      sign - A COSE_Sign object to verify.
      externalData - Optional external data.
      Returns:
      true if any of signatures in the COSE_Sign object is valid. false if none of signatures in the COSE_Sign object are valid.
      Throws:
      COSEException
    • verify

      public boolean verify(COSESign sign, COSESignature signature) throws COSEException
      Verify a combination of COSE_Sign and COSE_Signature.

      This method is an alias of verify(sign, signature, (byte[])null).

      Parameters:
      sign - A COSE_Sign object to verify.
      signature - A COSE_Signature object to verify.
      Returns:
      true if the signature of the COSE_Signature object is valid. false if the signature is invalid.
      Throws:
      COSEException
    • verify

      public boolean verify(COSESign sign, COSESignature signature, byte[] externalData) throws COSEException
      Verify a combination of COSE_Sign and COSE_Signature.

      This method is called repeatedly from within verify(COSESign, byte[]) for each COSE_Signature object in the COSE_Sign object.

      Parameters:
      sign - A COSE_Sign object to verify.
      signature - A COSE_Signature object to verify.
      externalData - Optional external data.
      Returns:
      true if the signature of the COSE_Signature object is valid. false if the signature is invalid.
      Throws:
      COSEException
    • verify

      public boolean verify(COSESign1 sign1) throws COSEException
      Verify a COSE_Sign1 object.

      This method is an alias of verify(sign1, (byte[])null).

      Parameters:
      sign1 - A COSE_Sign1 object to verify.
      Returns:
      true if the signature of the COSE_Sign1 object is valid. false if the signature is invalid.
      Throws:
      COSEException
    • verify

      public boolean verify(COSESign1 sign1, byte[] externalData) throws COSEException
      Verify a COSE_Sign1 object.
      Parameters:
      sign1 - A COSE_Sign1 object to verify.
      externalData - Optional external data.
      Returns:
      true if the signature of the COSE_Sign1 object is valid. false if the signature is invalid.
      Throws:
      COSEException
    • verify

      public static boolean verify(Key key, int alg, byte[] data, byte[] signature) throws COSEException
      Verify the signature for the data with the key and the algorithm.

      This method can be used for general purposes without depending on COSE data structures such as COSE_Sign and COSE_Sign1.

      Parameters:
      key - A public key for verification.
      alg - The integer identifier of an algorithm such as -7 (which means ES256). Identifiers are listed in IANA: COSE Algorithms.
      data - Data for which the signature was generated.
      signature - A signature to verify.
      Returns:
      true if the signature is valid. false if the signature is invalid.
      Throws:
      COSEException