- All Superinterfaces:
WebCertificateReference
,WebKeyReference
- All Known Implementing Classes:
Jwk
Unifies algorithm support and maps a cryptographic key from JCE to JSON Web
Key.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enum
Enumerates supported signature and encryption algorithms.static interface
WebKey.Builder<B extends WebKey.Builder<B>>
Builder interface for creatingWebKey
instances.static enum
Enumerates key operations.static enum
Enumerates key type.static enum
Enumerates public key use. -
Method Summary
Modifier and TypeMethodDescriptionstatic AlgorithmParameterSpec
algorithmParams
(String name) Gets theECParameterSpec
for a standard parameter name.static AlgorithmParameterSpec
algorithmParams
(Key key) Gets theAlgorithmParameterSpec
from a key.static String
SerializesWebKey
s as a JSON Web Key Set.static WebKey.Builder
<?> builder
(WebKey.Algorithm algorithm) Creates an ephemeral key for use as JWE recipient or JWS issuer.static WebKey.Builder
<?> builder
(WebKey.Type type) Creates a newWebKey.Builder
.static WebKey.Builder
<?> Creates a new builder.static WebKey
ephemeral
(WebEncryption.Encryption encryption) Creates an ephemeral content encryption key, for use withWebKey.Algorithm.DIRECT
.static WebKey
ephemeral
(WebKey.Algorithm algorithm) Creates an ephemeral key for use as JWE recipient or JWS issuer.byte[]
getKey()
Gets the raw key data for use whenWebKey.Type.RAW
.getOps()
Gets the key operations.Gets the JCE private key implementation.Gets the JCE public key implementation.getType()
Gets the key type.getUse()
Gets the public key use.static WebKey
Parses a JSON Web Key (JWK).Parses a JSON Web Key Set (JWKS).static WebKey
Reads at least one PEM-encoded X509 certificate, and optionally a private key, and returns a JWK partial-key representation.readJwks
(InputStream jwks) Reads a JSON Web Key Set (JWKS).Reads a JSON Web Key Set (JWKS).static PublicKey
Verifies encoded key data is correct for the key type, use, algorithm, and X.509 certificate chain.Returns a copy of this key for whichgetPrivateKey()
andgetKey()
always return null, and for which the source data backing these methods is not populated.static void
writeJwks
(Iterable<? extends WebKey> webKeys, OutputStream out) WritesWebKey
as a JSON Web Key.Methods inherited from interface edu.iu.crypt.WebCertificateReference
getCertificateChain, getCertificateSha256Thumbprint, getCertificateThumbprint, getCertificateUri
Methods inherited from interface edu.iu.crypt.WebKeyReference
getAlgorithm, getKeyId
-
Method Details
-
algorithmParams
Gets theECParameterSpec
for a standard parameter name.- Parameters:
name
- standard parameter name- Returns:
- Elliptic Curve parameters
-
algorithmParams
Gets theAlgorithmParameterSpec
from a key.- Parameters:
key
- key- Returns:
AlgorithmParameterSpec
-
verify
Verifies encoded key data is correct for the key type, use, algorithm, and X.509 certificate chain.- Parameters:
webKey
-WebKey
- Returns:
PublicKey
resolved from the web key, or null if no public key was resolved; private and raw key values will be verified as valid for the key type and/or public key, and may continue to be accessed from the original web key as needed.- Throws:
IllegalArgumentException
- if the key is invalid
-
builder
Creates a new builder.- Parameters:
key
- JCE key- Returns:
WebKey.Builder
-
builder
Creates a newWebKey.Builder
.- Parameters:
type
- key type- Returns:
WebKey.Builder
-
builder
Creates an ephemeral key for use as JWE recipient or JWS issuer.Ephemeral keys are generated using JDK 11 compliant standard algorithms with
registered JCE providers
- Parameters:
algorithm
- key algorithm- Returns:
- JWE recipient or JWS issuer key
-
ephemeral
Creates an ephemeral content encryption key, for use withWebKey.Algorithm.DIRECT
.Ephemeral keys are generated using JDK 11 compliant standard algorithms with
registered JCE providers
- Parameters:
encryption
- encryption algorithm- Returns:
- content encryption key
-
ephemeral
Creates an ephemeral key for use as JWE recipient or JWS issuer.Ephemeral keys are generated using JDK 11 compliant standard algorithms with
registered JCE providers
- Parameters:
algorithm
- key algorithm- Returns:
- JWE recipient or JWS issuer key
-
parse
Parses a JSON Web Key (JWK).- Parameters:
jwk
- JSON Web Key- Returns:
WebKey
-
parseJwks
Parses a JSON Web Key Set (JWKS).- Parameters:
jwks
- serialized JWKS- Returns:
- parsed key set
-
pem
Reads at least one PEM-encoded X509 certificate, and optionally a private key, and returns a JWK partial-key representation.- Parameters:
pem
- PEM-encoded certificate(s) and optional private key- Returns:
WebKey
-
readJwks
Reads a JSON Web Key Set (JWKS).- Parameters:
jwks
- serialized JWKS- Returns:
- parsed key set
-
readJwks
Reads a JSON Web Key Set (JWKS).- Parameters:
jwks
- serialized JWKS- Returns:
- parsed key set
-
asJwks
SerializesWebKey
s as a JSON Web Key Set.- Parameters:
webKeys
-WebKey
s- Returns:
- serialized JWKS
-
writeJwks
WritesWebKey
as a JSON Web Key.- Parameters:
webKeys
-WebKey
sout
-OutputStream
-
wellKnown
WebKey wellKnown()Returns a copy of this key for whichgetPrivateKey()
andgetKey()
always return null, and for which the source data backing these methods is not populated.If these methods would already return null, this key is returned as-is.
- Returns:
- this key, or a copy that omits secret and private key data
-
getType
WebKey.Type getType()Gets the key type.- Returns:
- key type
-
getUse
WebKey.Use getUse()Gets the public key use.- Returns:
- public key use.
-
getOps
Set<WebKey.Operation> getOps()Gets the key operations.- Returns:
- key operations
-
getKey
byte[] getKey()Gets the raw key data for use whenWebKey.Type.RAW
.- Returns:
- raw key data
-
getPrivateKey
PrivateKey getPrivateKey()Gets the JCE private key implementation.- Returns:
PrivateKey
-
getPublicKey
PublicKey getPublicKey()Gets the JCE public key implementation.- Returns:
PublicKey
-