/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Key implementation for RSA private keys, CRT form. For non-CRT private
* keys, see RSAPrivateKeyImpl. We need separate classes to ensure
* correct behavior in instanceof checks, etc.
*
* Note: RSA keys must be at least 512 bits long
*
* @see RSAPrivateKeyImpl
* @see RSAKeyFactory
*
* @since 1.5
* @author Andreas Sterbenz
*/
public final class RSAPrivateCrtKeyImpl
extends PKCS8Key implements RSAPrivateCrtKey {
private BigInteger n; // modulus
private BigInteger e; // public exponent
private BigInteger d; // private exponent
private BigInteger p; // prime p
private BigInteger q; // prime q
// algorithmId used to identify RSA keys
/**
* Generate a new key from its encoding. Returns a CRT key if possible
* and a non-CRT key otherwise. Used by RSAKeyFactory.
*/
throws InvalidKeyException {
// public exponent is missing, return a non-CRT key
return new RSAPrivateKeyImpl(
key.getModulus(),
);
} else {
return key;
}
}
/**
* Construct a key from its encoding. Called from newKey above.
*/
}
/**
* Construct a key from its components. Used by the
* RSAKeyFactory and the RSAKeyPairGenerator.
*/
this.n = n;
this.e = e;
this.d = d;
this.p = p;
this.q = q;
// generate the encoding
try {
out.putInteger(n);
out.putInteger(e);
out.putInteger(d);
out.putInteger(p);
out.putInteger(q);
} catch (IOException exc) {
// should never occur
throw new InvalidKeyException(exc);
}
}
// see JCA doc
return "RSA";
}
// see JCA doc
return n;
}
// see JCA doc
return e;
}
// see JCA doc
return d;
}
// see JCA doc
return p;
}
// see JCA doc
return q;
}
// see JCA doc
return pe;
}
// see JCA doc
return qe;
}
// see JCA doc
return coeff;
}
/**
* Parse the key. Called by PKCS8Key.
*/
try {
throw new IOException("Not a SEQUENCE");
}
if (version != 0) {
throw new IOException("Version must be 0");
}
n = getBigInteger(data);
e = getBigInteger(data);
d = getBigInteger(data);
p = getBigInteger(data);
q = getBigInteger(data);
throw new IOException("Extra data available");
}
} catch (IOException e) {
throw new InvalidKeyException("Invalid RSA private key", e);
}
}
/**
* Read a BigInteger from the DerInputStream.
*/
/*
* Some implementations do not correctly encode ASN.1 INTEGER values
* in 2's complement format, resulting in a negative integer when
* decoded. Correct the error by converting it to a positive integer.
*
* See CR 6255949
*/
if (b.signum() < 0) {
}
return b;
}
// return a string representation of this key for debugging
}
}