io.jsonwebtoken.security.OctetPrivateJwk Maven / Gradle / Ivy
/*
* Copyright © 2023 jsonwebtoken.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.jsonwebtoken.security;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.interfaces.ECPrivateKey;
/**
* JWK representation of an Edwards Curve
* {@link PrivateKey} as defined by RFC 8037, Section 2:
* Key Type "OKP".
*
* Unlike the {@link EcPrivateJwk} interface, which only supports
* Weierstrass-form {@link ECPrivateKey}s,
* {@code OctetPrivateJwk} allows for multiple parameterized {@link PrivateKey} types
* because the JDK supports two different types of Edwards Curve private keys:
*
* - java.security.interfaces.XECPrivateKey, introduced in JDK 11, and
* - java.security.interfaces.EdECPrivateKey, introduced in JDK 15.
*
* As such, {@code OctetPrivateJwk} is parameterized to support both key types.
*
* Earlier JDK Versions
*
* Even though {@code XECPrivateKey} and {@code EdECPrivateKey} were introduced in JDK 11 and JDK 15 respectively,
* JJWT supports Octet private JWKs in earlier versions when BouncyCastle is enabled in the application classpath. When
* using earlier JDK versions, the {@code OctetPrivateJwk} instance will need be parameterized with the
* generic {@code PrivateKey} type since the latter key types would not be present. For example:
*
* OctetPrivateJwk<PrivateKey> octetPrivateJwk = getKey();
*
* OKP-specific Properties
*
* Note that the various OKP-specific properties are not available as separate dedicated getter methods, as most Java
* applications should rarely, if ever, need to access these individual key properties since they typically represent
* internal key material and/or serialization details. If you need to access these key properties, it is usually
* recommended to obtain the corresponding {@link PrivateKey} instance returned by {@link #toKey()} and
* query that instead.
*
* Even so, because these properties exist and are readable by nature of every JWK being a
* {@link java.util.Map Map}, they are still accessible via the standard {@code Map} {@link #get(Object) get} method
* using an appropriate JWK parameter id, for example:
*
* jwk.get("x");
* jwk.get("d");
* // ... etc ...
*
* @param The type of Edwards-curve {@link PrivateKey} represented by this JWK (e.g. XECPrivateKey, EdECPrivateKey, etc).
* @param The type of Edwards-curve {@link PublicKey} represented by the JWK's corresponding
* {@link #toPublicJwk() public JWK}, for example XECPublicKey, EdECPublicKey, etc.
* @since 0.12.0
*/
public interface OctetPrivateJwk extends PrivateJwk> {
}