Package COSE

Class OneKey


  • public class OneKey
    extends Object
    Author:
    jimsch
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected com.upokecenter.cbor.CBORObject keyMap  
    • Constructor Summary

      Constructors 
      Constructor Description
      OneKey()  
      OneKey​(com.upokecenter.cbor.CBORObject keyData)  
      OneKey​(PublicKey pubKey, PrivateKey privKey)
      Create a OneKey object from Java Public/Private keys.
    • Method Summary

      Modifier and Type Method Description
      void add​(com.upokecenter.cbor.CBORObject keyValue, com.upokecenter.cbor.CBORObject value)  
      void add​(KeyKeys keyValue, com.upokecenter.cbor.CBORObject value)  
      com.upokecenter.cbor.CBORObject AsCBOR()
      Return the key as a CBOR object
      PrivateKey AsPrivateKey()
      Return a java.security.PrivateKey that is the same as the OneKey key
      PublicKey AsPublicKey()
      Return a java.security.PublicKey that is the same as the OneKey key
      byte[] EncodeToBytes()
      Encode to a byte string
      static OneKey generateKey​(com.upokecenter.cbor.CBORObject curve)  
      static OneKey generateKey​(AlgorithmID algorithm)  
      static OneKey generateKey​(AlgorithmID algorithm, String parameters)
      Generate a random key pair based on the given algorithm.
      com.upokecenter.cbor.CBORObject get​(com.upokecenter.cbor.CBORObject keyValue)  
      com.upokecenter.cbor.CBORObject get​(KeyKeys keyValue)  
      ECGenParameterSpec GetCurve2()  
      Object getUserData()
      Return the user data field.
      boolean HasAlgorithmID​(AlgorithmID algorithmId)
      Compares the key's assigned algorithm with the provided value, indicating if the values are the same.
      boolean HasKeyID​(byte[] id)  
      boolean HasKeyID​(String id)
      Deprecated.
      boolean HasKeyOp​(Integer that)
      Compares the key's assigned key operations with the provided value, indicating if the provided value was found in the key operation values assigned to the key.
      boolean HasKeyType​(com.upokecenter.cbor.CBORObject keyTypeObj)
      Compares the key's assigned key type with the provided value, indicating if the values are the same.
      OneKey PublicKey()
      Create a OneKey object with only the public fields.
      void setUserData​(Object newData)
      Set the user data field.
    • Field Detail

      • keyMap

        protected com.upokecenter.cbor.CBORObject keyMap
    • Constructor Detail

      • OneKey

        public OneKey()
      • OneKey

        public OneKey​(PublicKey pubKey,
                      PrivateKey privKey)
               throws CoseException
        Create a OneKey object from Java Public/Private keys.
        Parameters:
        pubKey - - public key to use - may be null
        privKey - - private key to use - may be null
        Throws:
        CoseException - Internal COSE Exception
    • Method Detail

      • add

        public void add​(KeyKeys keyValue,
                        com.upokecenter.cbor.CBORObject value)
      • add

        public void add​(com.upokecenter.cbor.CBORObject keyValue,
                        com.upokecenter.cbor.CBORObject value)
      • get

        public com.upokecenter.cbor.CBORObject get​(KeyKeys keyValue)
      • get

        public com.upokecenter.cbor.CBORObject get​(com.upokecenter.cbor.CBORObject keyValue)
                                            throws CoseException
        Throws:
        CoseException
      • HasAlgorithmID

        public boolean HasAlgorithmID​(AlgorithmID algorithmId)
        Compares the key's assigned algorithm with the provided value, indicating if the values are the same.
        Parameters:
        algorithmId - the algorithm to compare or null to check for no assignment.
        Returns:
        true if the current key has the provided algorithm assigned, or false otherwise
      • HasKeyID

        @Deprecated
        public boolean HasKeyID​(String id)
        Deprecated.
        Compares the key's assigned identifier with the provided value, indicating if the values are the same.
        Parameters:
        id - the identifier to compare or null to check for no assignment.
        Returns:
        true if the current key has the provided identifier assigned, or false otherwise
      • HasKeyID

        public boolean HasKeyID​(byte[] id)
      • HasKeyType

        public boolean HasKeyType​(com.upokecenter.cbor.CBORObject keyTypeObj)
        Compares the key's assigned key type with the provided value, indicating if the values are the same.
        Parameters:
        keyTypeObj - the key type to compare or null to check for no assignment.
        Returns:
        true if the current key has the provided identifier assigned, or false otherwise
      • HasKeyOp

        public boolean HasKeyOp​(Integer that)
        Compares the key's assigned key operations with the provided value, indicating if the provided value was found in the key operation values assigned to the key.
        Parameters:
        that - the integer operation value to attempt to find in the values provided by the key or null to check for no assignment.
        Returns:
        true if the current key has the provided value assigned, or false otherwise
      • generateKey

        public static OneKey generateKey​(AlgorithmID algorithm,
                                         String parameters)
                                  throws CoseException
        Generate a random key pair based on the given algorithm. Some algorithm can take a parameter. For example, the RSA_PSS family of algorithm can take the RSA key size as a parameter.
        Parameters:
        algorithm - the algorithm to generate a key pair for
        parameters - optional parameters to the key pair generator
        Returns:
        the generated Key Pair
        Throws:
        CoseException
      • PublicKey

        public OneKey PublicKey()
        Create a OneKey object with only the public fields. Filters out the private key fields but leaves all positive number labels and text labels along with negative number labels that are public fields.
        Returns:
        public version of the key
      • EncodeToBytes

        public byte[] EncodeToBytes()
        Encode to a byte string
        Returns:
        encoded object as bytes.
      • AsCBOR

        public com.upokecenter.cbor.CBORObject AsCBOR()
        Return the key as a CBOR object
        Returns:
        The key
      • AsPublicKey

        public PublicKey AsPublicKey()
                              throws CoseException
        Return a java.security.PublicKey that is the same as the OneKey key
        Returns:
        the key
        Throws:
        CoseException - If there is a conversion error
      • AsPrivateKey

        public PrivateKey AsPrivateKey()
                                throws CoseException
        Return a java.security.PrivateKey that is the same as the OneKey key
        Returns:
        the key
        Throws:
        CoseException - if there is a conversion error
      • getUserData

        public Object getUserData()
        Return the user data field. The user data object allows for an application to associate a piece of arbitrary data with a key and retrieve it later.
        Returns:
        the user data object
      • setUserData

        public void setUserData​(Object newData)
        Set the user data field. The user data field allows for an application to associate a piece of arbitrary data with a key and retrieve it later.
        Parameters:
        newData - Data field to be saved.