@Immutable public final class OctetSequenceKey extends JWK implements SecretJWK
Octet sequence
JSON Web Key (JWK), used to represent
symmetric keys. This class is immutable.
Octet sequence JWKs should specify the algorithm intended to be used with the key, unless the application uses other means or convention to determine the algorithm used.
Example JSON object representation of an octet sequence JWK:
{ "kty" : "oct", "alg" : "A128KW", "k" : "GawgguFyGrWKav7AX4VKUg" }
Use the builder to create a new octet JWK:
OctetSequenceKey key = new OctetSequenceKey.Builder(bytes) .keyID("123") .build();
Modifier and Type | Class and Description |
---|---|
static class |
OctetSequenceKey.Builder
Builder for constructing octet sequence JWKs.
|
Constructor and Description |
---|
OctetSequenceKey(Base64URL k,
KeyUse use,
Set<KeyOperation> ops,
Algorithm alg,
String kid,
URI x5u,
Base64URL x5t,
Base64URL x5t256,
List<Base64> x5c,
KeyStore ks)
Creates a new octet sequence JSON Web Key (JWK) with the specified
parameters.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
Base64URL |
getKeyValue()
Returns the value of this octet sequence key.
|
LinkedHashMap<String,?> |
getRequiredParams()
Returns the required JWK parameters.
|
int |
hashCode() |
boolean |
isPrivate()
Octet sequence (symmetric) keys are never considered public, this
method always returns
true . |
static OctetSequenceKey |
load(KeyStore keyStore,
String alias,
char[] pin)
Loads an octet sequence JWK from the specified JCA key store.
|
static OctetSequenceKey |
parse(net.minidev.json.JSONObject jsonObject)
Parses an octet sequence JWK from the specified JSON object
representation.
|
static OctetSequenceKey |
parse(String s)
Parses an octet sequence JWK from the specified JSON object string
representation.
|
int |
size()
Returns the size of this JWK.
|
byte[] |
toByteArray()
Returns a copy of this octet sequence key value as a byte array.
|
net.minidev.json.JSONObject |
toJSONObject()
Returns a JSON object representation of this JWK.
|
OctetSequenceKey |
toPublicJWK()
Octet sequence (symmetric) keys are never considered public, this
method always returns
null . |
SecretKey |
toSecretKey()
Returns a secret key representation of this octet sequence key.
|
SecretKey |
toSecretKey(String jcaAlg)
Returns a secret key representation of this octet sequence key with
the specified Java Cryptography Architecture (JCA) algorithm.
|
computeThumbprint, computeThumbprint, getAlgorithm, getKeyID, getKeyOperations, getKeyStore, getKeyType, getKeyUse, getParsedX509CertChain, getX509CertChain, getX509CertSHA256Thumbprint, getX509CertThumbprint, getX509CertURL, parse, parseFromPEMEncodedObjects, parseFromPEMEncodedX509Cert, toJSONString, toString
public OctetSequenceKey(Base64URL k, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks)
k
- The key value. It is represented as the Base64URL
encoding of the value's big endian representation.
Must not be null
.use
- The key use, null
if not specified or if the
key is intended for signing as well as encryption.ops
- The key operations, null
if not specified.alg
- The intended JOSE algorithm for the key, null
if not specified.kid
- The key ID. null
if not specified.x5u
- The X.509 certificate URL, null
if not specified.x5t
- The X.509 certificate SHA-1 thumbprint, null
if not specified.x5t256
- The X.509 certificate SHA-256 thumbprint, null
if not specified.x5c
- The X.509 certificate chain, null
if not
specified.ks
- Reference to the underlying key store, null
if
not specified.public Base64URL getKeyValue()
public byte[] toByteArray()
public SecretKey toSecretKey()
toSecretKey
in interface SecretJWK
NONE
.public SecretKey toSecretKey(String jcaAlg)
jcaAlg
- The JCA algorithm. Must not be null
.public LinkedHashMap<String,?> getRequiredParams()
JWK
getRequiredParams
in class JWK
public boolean isPrivate()
true
.public OctetSequenceKey toPublicJWK()
null
.toPublicJWK
in class JWK
null
public net.minidev.json.JSONObject toJSONObject()
JWK
Example:
{ "kty" : "RSA", "use" : "sig", "kid" : "fd28e025-8d24-48bc-a51a-e2ffc8bc274b" }
toJSONObject
in class JWK
public static OctetSequenceKey parse(String s) throws ParseException
s
- The JSON object string to parse. Must not be null
.ParseException
- If the string couldn't be parsed to an octet
sequence JWK.public static OctetSequenceKey parse(net.minidev.json.JSONObject jsonObject) throws ParseException
jsonObject
- The JSON object to parse. Must not be
null
.ParseException
- If the JSON object couldn't be parsed to an
octet sequence JWK.public static OctetSequenceKey load(KeyStore keyStore, String alias, char[] pin) throws KeyStoreException, JOSEException
keyStore
- The key store. Must not be null
.alias
- The alias. Must not be null
.pin
- The pin to unlock the private key if any, empty or
null
if not required.null
if no key with the
specified alias was found.KeyStoreException
- On a key store exception.JOSEException
- If octet sequence key loading failed.Copyright © 2019 Connect2id Ltd.. All rights reserved.