001/*
002 * nimbus-jose-jwt
003 *
004 * Copyright 2012-2016, Connect2id Ltd.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
007 * this file except in compliance with the License. You may obtain a copy of the
008 * License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed
013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations under the License.
016 */
017
018package com.nimbusds.jose.jwk;
019
020
021import java.security.KeyPair;
022import java.security.PrivateKey;
023import java.security.PublicKey;
024import java.security.cert.X509Certificate;
025
026import com.nimbusds.jose.JOSEException;
027
028
029/**
030 * Asymmetric (pair) JSON Web Key (JWK).
031 *
032 * @author Vladimir Dzhuvinov
033 * @version 2018-02-27
034 */
035public interface AsymmetricJWK {
036        
037
038        /**
039         * Returns a Java public key representation of the JWK.
040         *
041         * @return The Java public key.
042         *
043         * @throws JOSEException If conversion failed or is not supported.
044         */
045        PublicKey toPublicKey()
046                throws JOSEException;
047
048
049        /**
050         * Returns a Java private key representation of this JWK.
051         *
052         * @return The Java private key, {@code null} if not specified.
053         *
054         * @throws JOSEException If conversion failed or is not supported.
055         */
056        PrivateKey toPrivateKey()
057                throws JOSEException;
058
059
060        /**
061         * Returns a Java key pair representation of this JWK.
062         *
063         * @return The Java key pair. The private key will be {@code null} if
064         *         not specified.
065         *
066         * @throws JOSEException If conversion failed or is not supported.
067         */
068        KeyPair toKeyPair()
069                throws JOSEException;
070        
071        
072        /**
073         * Returns {@code true} if the public key material of this JWK matches
074         * the public subject key info of the specified X.509 certificate.
075         *
076         * @param cert The X.509 certificate. Must not be {@code null}.
077         *
078         * @return {@code true} if the public key material of this JWK matches
079         *         the public subject key info of the specified X.509
080         *         certificate, else {@code false}.
081         */
082        boolean matches(X509Certificate cert);
083}