Package COSE
Class OneKey
- java.lang.Object
-
- COSE.OneKey
-
public class OneKey extends Object
- Author:
- jimsch
-
-
Field Summary
Fields Modifier and Type Field Description protected com.upokecenter.cbor.CBORObjectkeyMap
-
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 voidadd(com.upokecenter.cbor.CBORObject keyValue, com.upokecenter.cbor.CBORObject value)voidadd(KeyKeys keyValue, com.upokecenter.cbor.CBORObject value)com.upokecenter.cbor.CBORObjectAsCBOR()Return the key as a CBOR objectPrivateKeyAsPrivateKey()Return a java.security.PrivateKey that is the same as the OneKey keyPublicKeyAsPublicKey()Return a java.security.PublicKey that is the same as the OneKey keybyte[]EncodeToBytes()Encode to a byte stringstatic OneKeygenerateKey(com.upokecenter.cbor.CBORObject curve)static OneKeygenerateKey(AlgorithmID algorithm)static OneKeygenerateKey(AlgorithmID algorithm, String parameters)Generate a random key pair based on the given algorithm.com.upokecenter.cbor.CBORObjectget(com.upokecenter.cbor.CBORObject keyValue)com.upokecenter.cbor.CBORObjectget(KeyKeys keyValue)ECGenParameterSpecGetCurve2()ObjectgetUserData()Return the user data field.booleanHasAlgorithmID(AlgorithmID algorithmId)Compares the key's assigned algorithm with the provided value, indicating if the values are the same.booleanHasKeyID(byte[] id)booleanHasKeyID(String id)Deprecated.booleanHasKeyOp(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.booleanHasKeyType(com.upokecenter.cbor.CBORObject keyTypeObj)Compares the key's assigned key type with the provided value, indicating if the values are the same.OneKeyPublicKey()Create a OneKey object with only the public fields.voidsetUserData(Object newData)Set the user data field.
-
-
-
Constructor Detail
-
OneKey
public OneKey()
-
OneKey
public OneKey(com.upokecenter.cbor.CBORObject keyData) throws CoseException- Throws:
CoseException
-
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 nullprivKey- - 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 ornullto check for no assignment.- Returns:
trueif the current key has the provided algorithm assigned, orfalseotherwise
-
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 ornullto check for no assignment.- Returns:
trueif the current key has the provided identifier assigned, orfalseotherwise
-
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 ornullto check for no assignment.- Returns:
trueif the current key has the provided identifier assigned, orfalseotherwise
-
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 ornullto check for no assignment.- Returns:
trueif the current key has the provided value assigned, orfalseotherwise
-
GetCurve2
public ECGenParameterSpec GetCurve2() throws CoseException
- Throws:
CoseException
-
generateKey
public static OneKey generateKey(AlgorithmID algorithm) throws CoseException
- Throws:
CoseException
-
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 forparameters- optional parameters to the key pair generator- Returns:
- the generated Key Pair
- Throws:
CoseException
-
generateKey
public static OneKey generateKey(com.upokecenter.cbor.CBORObject curve) throws CoseException
- 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.
-
-