Path: blob/master/src/java.base/share/classes/java/security/KeyPair.java
41152 views
/*1* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.security;2627import java.util.*;2829/**30* This class is a simple holder for a key pair (a public key and a31* private key). It does not enforce any security, and, when initialized,32* should be treated like a PrivateKey.33*34* @see PublicKey35* @see PrivateKey36*37* @author Benjamin Renaud38* @since 1.139*/4041public final class KeyPair implements java.io.Serializable {4243@java.io.Serial44private static final long serialVersionUID = -7565189502268009837L;4546/** The private key. */47private PrivateKey privateKey;4849/** The public key. */50private PublicKey publicKey;5152/**53* Constructs a key pair from the given public key and private key.54*55* <p>Note that this constructor only stores references to the public56* and private key components in the generated key pair. This is safe,57* because {@code Key} objects are immutable.58*59* @param publicKey the public key.60*61* @param privateKey the private key.62*/63public KeyPair(PublicKey publicKey, PrivateKey privateKey) {64this.publicKey = publicKey;65this.privateKey = privateKey;66}6768/**69* Returns a reference to the public key component of this key pair.70*71* @return a reference to the public key.72*/73public PublicKey getPublic() {74return publicKey;75}7677/**78* Returns a reference to the private key component of this key pair.79*80* @return a reference to the private key.81*/82public PrivateKey getPrivate() {83return privateKey;84}85}868788