Class COSEKey
- Direct Known Subclasses:
COSEEC2Key
,COSEOKPKey
Subclasses should override the following methods.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addJwkProperties
(Map<String, Object> map) Add JWK properties to the given map.static COSEKey
Build an instance ofCOSEKey
or its subclass when possible (e.g.static COSEKey
Build an instance ofCOSEKey
or its subclass when possible (e.g.copy()
Copy thisCOSEKey
instance.Create aPrivateKey
instance from this COSE key.Create aPublicKey
instance from this COSE key.static COSEKey
Build aCOSEKey
instance from a map that represents a JWK (JSON Web Key).getAlg()
Get the value of the "alg (3)" parameter.byte[]
Get the value of the "Base IV (5)" parameter.Get the value of the "key_ops (4)" parameter.byte[]
getKid()
Get the value of the "kid (2)" parameter.getKty()
Get the value of the "kty (1)" parameter.Get the set of parameters of this key as aMap
.boolean
Get the flag indicating whether this key contains private parameters.toJwk()
Convert this key to aMap
instance that represents a JWK (RFC 7517 JSON Web Key (JWK)).toPublic()
Convert this COSE key to a public key.Methods inherited from class com.authlete.cbor.CBORPairList
encode, findByKey, getPairs, parse, prettify, toString
Methods inherited from class com.authlete.cbor.CBORItem
encode, encodeMajorWithNumber, encodeToBase64, encodeToBase64Url, encodeToHex, getComment, prettify, setComment, toString
-
Constructor Details
-
COSEKey
-
-
Method Details
-
getParameters
-
getKty
Get the value of the "kty (1)" parameter.The type of the value is an integer (
int
,long
orBigInteger
) or a string (String
).- Returns:
- The value of the "kty (1)" parameter.
- See Also:
-
getKid
public byte[] getKid()Get the value of the "kid (2)" parameter.- Returns:
- The value of the "kid (2)" parameter. If the parameter is not
contained,
null
is returned.
-
getAlg
Get the value of the "alg (3)" parameter.The type of the value is an integer (
int
,long
orBigInteger
) or a string (String
).- Returns:
- The value of the "alg (3)" parameter. If the parameter is not
contained,
null
is returned. - See Also:
-
getKeyOps
-
getBaseIv
public byte[] getBaseIv()Get the value of the "Base IV (5)" parameter.- Returns:
- The value of the "Base IV (5)" parameter. If the parameter is
not contained,
null
is returned.
-
isPrivate
public boolean isPrivate()Get the flag indicating whether this key contains private parameters.Subclasses of the
COSEKey
class are expected to override this method.- Returns:
true
if this key contains private parameters.- Since:
- 1.3
-
toPublic
Convert this COSE key to a public key.When this
COSEKey
instance is a public key, this method returnsthis
object without any modification. Otherwise, this method creates a newCOSEKey
instance representing a public key and returns the new instance.The default implementation of this method throws an exception. Subclasses should override this method.
- Returns:
- A
COSEKey
instance representing a public key. - Throws:
COSEException
- Since:
- 1.15
-
createPrivateKey
Create aPrivateKey
instance from this COSE key.The default implementation of this method throws an exception. Subclasses should override this method.
- Returns:
- A
PrivateKey
instance. - Throws:
COSEException
- The creation failed.- Since:
- 1.15
-
createPublicKey
Create aPublicKey
instance from this COSE key.The default implementation of this method throws an exception. Subclasses should override this method.
- Returns:
- A
PublicKey
instance. - Throws:
COSEException
- The creation failed.- Since:
- 1.15
-
copy
Copy thisCOSEKey
instance.- Returns:
- A new
COSEKey
instance that holds the same content as thisCOSEKey
instance does. - Throws:
COSEException
- Copying this instance failed.- Since:
- 1.15
-
toJwk
Convert this key to aMap
instance that represents a JWK (RFC 7517 JSON Web Key (JWK)).Subclasses of the
COSEKey
class should override theaddJwkProperties(Map)
method to add JWK properties that are specific to them.- Returns:
- A
Map
instance that represents a JWK. - Since:
- 1.3
- See Also:
-
addJwkProperties
-
build
Build an instance ofCOSEKey
or its subclass when possible (e.g.COSEOKPKey
andCOSEEC2Key
) from the given CBOR data item.- Parameters:
item
- A CBOR data item that represents a COSE key. It must be a CBOR map.- Returns:
- An instance of
COSEKey
or its subclass. - Throws:
COSEException
-
build
Build an instance ofCOSEKey
or its subclass when possible (e.g.COSEOKPKey
andCOSEEC2Key
) from the given map.- Parameters:
map
- A map that represents a COSE key.- Returns:
- An instance of
COSEKey
or its subclass. - Throws:
COSEException
-
fromJwk
Build aCOSEKey
instance from a map that represents a JWK (JSON Web Key).- Parameters:
jwk
- A map that represents a JWK.- Returns:
- An instance of
COSEKey
or its subclass such asCOSEEC2Key
. - Throws:
COSEException
- Failed to create aCOSEKey
instance of the input map.- Since:
- 1.11
-