1 /* 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.security.spec; 27 28 import java.math.BigInteger; 29 30 /** 31 * This class specifies an RSA private key, as defined in the PKCS#1 32 * standard, using the Chinese Remainder Theorem (CRT) information values for 33 * efficiency. 34 * 35 * @author Jan Luehe 36 * @since 1.2 37 * 38 * 39 * @see java.security.Key 40 * @see java.security.KeyFactory 41 * @see KeySpec 42 * @see PKCS8EncodedKeySpec 43 * @see RSAPrivateKeySpec 44 * @see RSAPublicKeySpec 45 */ 46 47 public class RSAPrivateCrtKeySpec extends RSAPrivateKeySpec { 48 49 private final BigInteger publicExponent; 50 private final BigInteger primeP; 51 private final BigInteger primeQ; 52 private final BigInteger primeExponentP; 53 private final BigInteger primeExponentQ; 54 private final BigInteger crtCoefficient; 55 56 57 58 /** 59 * Creates a new {@code RSAPrivateCrtKeySpec} 60 * given the modulus, publicExponent, privateExponent, 61 * primeP, primeQ, primeExponentP, primeExponentQ, and 62 * crtCoefficient as defined in PKCS#1. 63 * 64 * @param modulus the modulus n 65 * @param publicExponent the public exponent e 66 * @param privateExponent the private exponent d 67 * @param primeP the prime factor p of n 68 * @param primeQ the prime factor q of n 69 * @param primeExponentP this is d mod (p-1) 70 * @param primeExponentQ this is d mod (q-1) 71 * @param crtCoefficient the Chinese Remainder Theorem 72 * coefficient q-1 mod p 73 */ 74 public RSAPrivateCrtKeySpec(BigInteger modulus, 75 BigInteger publicExponent, 76 BigInteger privateExponent, 77 BigInteger primeP, 78 BigInteger primeQ, 79 BigInteger primeExponentP, 80 BigInteger primeExponentQ, 81 BigInteger crtCoefficient) { 82 super(modulus, privateExponent); 83 this.publicExponent = publicExponent; 84 this.primeP = primeP; 85 this.primeQ = primeQ; 86 this.primeExponentP = primeExponentP; 87 this.primeExponentQ = primeExponentQ; 88 this.crtCoefficient = crtCoefficient; 89 } 90 91 /** 92 * Returns the public exponent. 93 * 94 * @return the public exponent 95 */ 96 public BigInteger getPublicExponent() { 97 return this.publicExponent; 98 } 99 100 /** 101 * Returns the primeP. 102 | 1 /* 2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.security.spec; 27 28 import java.math.BigInteger; 29 30 /** 31 * This class specifies an RSA private key, as defined in the 32 * <a href="https://tools.ietf.org/rfc/rfc8017.txt">PKCS#1 v2.2</a> standard, 33 * using the Chinese Remainder Theorem (CRT) information values for efficiency. 34 * 35 * @author Jan Luehe 36 * @since 1.2 37 * 38 * 39 * @see java.security.Key 40 * @see java.security.KeyFactory 41 * @see KeySpec 42 * @see PKCS8EncodedKeySpec 43 * @see RSAPrivateKeySpec 44 * @see RSAPublicKeySpec 45 */ 46 47 public class RSAPrivateCrtKeySpec extends RSAPrivateKeySpec { 48 49 private final BigInteger publicExponent; 50 private final BigInteger primeP; 51 private final BigInteger primeQ; 52 private final BigInteger primeExponentP; 53 private final BigInteger primeExponentQ; 54 private final BigInteger crtCoefficient; 55 56 /** 57 * Creates a new {@code RSAPrivateCrtKeySpec}. 58 * 59 * @param modulus the modulus n 60 * @param publicExponent the public exponent e 61 * @param privateExponent the private exponent d 62 * @param primeP the prime factor p of n 63 * @param primeQ the prime factor q of n 64 * @param primeExponentP this is d mod (p-1) 65 * @param primeExponentQ this is d mod (q-1) 66 * @param crtCoefficient the Chinese Remainder Theorem 67 * coefficient q-1 mod p 68 */ 69 public RSAPrivateCrtKeySpec(BigInteger modulus, 70 BigInteger publicExponent, 71 BigInteger privateExponent, 72 BigInteger primeP, 73 BigInteger primeQ, 74 BigInteger primeExponentP, 75 BigInteger primeExponentQ, 76 BigInteger crtCoefficient) { 77 this(modulus, publicExponent, privateExponent, primeP, primeQ, 78 primeExponentP, primeExponentQ, crtCoefficient, null); 79 } 80 81 /** 82 * Creates a new {@code RSAPrivateCrtKeySpec} with additional 83 * key parameters. 84 * 85 * @param modulus the modulus n 86 * @param publicExponent the public exponent e 87 * @param privateExponent the private exponent d 88 * @param primeP the prime factor p of n 89 * @param primeQ the prime factor q of n 90 * @param primeExponentP this is d mod (p-1) 91 * @param primeExponentQ this is d mod (q-1) 92 * @param crtCoefficient the Chinese Remainder Theorem 93 * coefficient q-1 mod p 94 * @param keyParams the parameters associated with key 95 * @since 11 96 */ 97 public RSAPrivateCrtKeySpec(BigInteger modulus, 98 BigInteger publicExponent, 99 BigInteger privateExponent, 100 BigInteger primeP, 101 BigInteger primeQ, 102 BigInteger primeExponentP, 103 BigInteger primeExponentQ, 104 BigInteger crtCoefficient, 105 AlgorithmParameterSpec keyParams) { 106 super(modulus, privateExponent, keyParams); 107 this.publicExponent = publicExponent; 108 this.primeP = primeP; 109 this.primeQ = primeQ; 110 this.primeExponentP = primeExponentP; 111 this.primeExponentQ = primeExponentQ; 112 this.crtCoefficient = crtCoefficient; 113 } 114 115 /** 116 * Returns the public exponent. 117 * 118 * @return the public exponent 119 */ 120 public BigInteger getPublicExponent() { 121 return this.publicExponent; 122 } 123 124 /** 125 * Returns the primeP. 126 |