Class COSESigner

java.lang.Object
com.authlete.cose.COSESigner
All Implemented Interfaces:
SigStructureSigner

public class COSESigner extends Object implements SigStructureSigner
A signer for COSE.
Since:
1.1
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    COSESigner(KeyGetter keyGetter)
    A constructor with a key getter that is called later when signing is performed.
    A constructor with a private key for signing.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    sign(SigStructure structure, int algorithm)
    Generate a signature for the Sig Structure with the specified algorithm.
    byte[]
    sign(SigStructure structure, int algorithm, byte[] keyID)
    Generate a signature for the Sig Structure with the specified algorithm.
    static byte[]
    sign(Key key, int alg, byte[] data)
    Generate a 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

    • COSESigner

      public COSESigner(Key key)
      A constructor with a private key for signing.
      Parameters:
      key - A private key for signing. Must not be null.
    • COSESigner

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

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

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

    • sign

      public byte[] sign(SigStructure structure, int algorithm) throws COSEException
      Generate a signature for the Sig Structure with the specified algorithm.
      Specified by:
      sign in interface SigStructureSigner
      Parameters:
      structure - A Sig Structure for which a signature is generated.
      algorithm - The integer identifier of an algorithm such as -7 (which means ES256). Identifiers are listed in IANA: COSE Algorithms.
      Returns:
      A generated signature.
      Throws:
      COSEException
    • sign

      public byte[] sign(SigStructure structure, int algorithm, byte[] keyID) throws COSEException
      Generate a signature for the Sig Structure with the specified algorithm.
      Parameters:
      structure - A Sig Structure for which a signature is generated.
      algorithm - The integer identifier of an algorithm such as -7 (which means ES256). Identifiers are listed in IANA: COSE Algorithms.
      keyID - The key ID of the private key to use. This argument has a meaning only when this COSESigner instance has been created with a key getter. The key ID is passed to the get method of the key getter.
      Returns:
      A generated signature.
      Throws:
      COSEException
    • sign

      public static byte[] sign(Key key, int alg, byte[] data) throws COSEException
      Generate a 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 Sig_structure.

      Parameters:
      key - A private key for signing.
      alg - The integer identifier of an algorithm such as -7 (which means ES256). Identifiers are listed in IANA: COSE Algorithms.
      data - Data for which a signature is generated.
      Returns:
      A generated signature.
      Throws:
      COSEException