01: package org.bouncycastle.jce.provider;
02:
03: import java.security.interfaces.RSAPrivateCrtKey;
04: import java.security.interfaces.RSAPrivateKey;
05: import java.security.interfaces.RSAPublicKey;
06:
07: import org.bouncycastle.asn1.DERObjectIdentifier;
08: import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
09: import org.bouncycastle.asn1.x509.X509ObjectIdentifiers;
10: import org.bouncycastle.crypto.params.RSAKeyParameters;
11: import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters;
12:
13: /**
14: * utility class for converting java.security RSA objects into their
15: * org.bouncycastle.crypto counterparts.
16: */
17: class RSAUtil {
18: static boolean isRsaOid(DERObjectIdentifier algOid) {
19: return algOid.equals(PKCSObjectIdentifiers.rsaEncryption)
20: || algOid.equals(X509ObjectIdentifiers.id_ea_rsa)
21: || algOid.equals(PKCSObjectIdentifiers.id_RSASSA_PSS)
22: || algOid.equals(PKCSObjectIdentifiers.id_RSAES_OAEP);
23: }
24:
25: static RSAKeyParameters generatePublicKeyParameter(RSAPublicKey key) {
26: return new RSAKeyParameters(false, key.getModulus(), key
27: .getPublicExponent());
28:
29: }
30:
31: static RSAKeyParameters generatePrivateKeyParameter(
32: RSAPrivateKey key) {
33: if (key instanceof RSAPrivateCrtKey) {
34: RSAPrivateCrtKey k = (RSAPrivateCrtKey) key;
35:
36: return new RSAPrivateCrtKeyParameters(k.getModulus(), k
37: .getPublicExponent(), k.getPrivateExponent(), k
38: .getPrimeP(), k.getPrimeQ(), k.getPrimeExponentP(),
39: k.getPrimeExponentQ(), k.getCrtCoefficient());
40: } else {
41: RSAPrivateKey k = key;
42:
43: return new RSAKeyParameters(true, k.getModulus(), k
44: .getPrivateExponent());
45: }
46: }
47: }
|