summaryrefslogtreecommitdiff
path: root/bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateKey.java
diff options
context:
space:
mode:
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateKey.java')
-rw-r--r--bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateKey.java56
1 files changed, 51 insertions, 5 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateKey.java b/bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateKey.java
index f529d9b8..f92a430a 100644
--- a/bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateKey.java
+++ b/bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateKey.java
@@ -10,7 +10,6 @@ import java.util.Enumeration;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
-import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.crypto.params.RSAKeyParameters;
@@ -28,18 +27,30 @@ public class BCRSAPrivateKey
protected BigInteger modulus;
protected BigInteger privateExponent;
+ private byte[] algorithmIdentifierEnc = getEncoding(BCRSAPublicKey.DEFAULT_ALGORITHM_IDENTIFIER);
- private transient PKCS12BagAttributeCarrierImpl attrCarrier = new PKCS12BagAttributeCarrierImpl();
+ protected transient AlgorithmIdentifier algorithmIdentifier = BCRSAPublicKey.DEFAULT_ALGORITHM_IDENTIFIER;
+ protected transient RSAKeyParameters rsaPrivateKey;
+ protected transient PKCS12BagAttributeCarrierImpl attrCarrier = new PKCS12BagAttributeCarrierImpl();
- protected BCRSAPrivateKey()
+ BCRSAPrivateKey(
+ RSAKeyParameters key)
{
+ this.modulus = key.getModulus();
+ this.privateExponent = key.getExponent();
+ this.rsaPrivateKey = key;
}
BCRSAPrivateKey(
+ AlgorithmIdentifier algID,
RSAKeyParameters key)
{
+ this.algorithmIdentifier = algID;
+ this.algorithmIdentifierEnc = getEncoding(algID);
+
this.modulus = key.getModulus();
this.privateExponent = key.getExponent();
+ this.rsaPrivateKey = key;
}
BCRSAPrivateKey(
@@ -47,6 +58,7 @@ public class BCRSAPrivateKey
{
this.modulus = spec.getModulus();
this.privateExponent = spec.getPrivateExponent();
+ this.rsaPrivateKey = new RSAKeyParameters(true, modulus, privateExponent);
}
BCRSAPrivateKey(
@@ -54,12 +66,17 @@ public class BCRSAPrivateKey
{
this.modulus = key.getModulus();
this.privateExponent = key.getPrivateExponent();
+ this.rsaPrivateKey = new RSAKeyParameters(true, modulus, privateExponent);
}
- BCRSAPrivateKey(org.bouncycastle.asn1.pkcs.RSAPrivateKey key)
+ BCRSAPrivateKey(AlgorithmIdentifier algID, org.bouncycastle.asn1.pkcs.RSAPrivateKey key)
{
+ this.algorithmIdentifier = algID;
+ this.algorithmIdentifierEnc = getEncoding(algID);
+
this.modulus = key.getModulus();
this.privateExponent = key.getPrivateExponent();
+ this.rsaPrivateKey = new RSAKeyParameters(true, modulus, privateExponent);
}
public BigInteger getModulus()
@@ -74,6 +91,10 @@ public class BCRSAPrivateKey
public String getAlgorithm()
{
+ if (algorithmIdentifier.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS))
+ {
+ return "RSASSA-PSS";
+ }
return "RSA";
}
@@ -82,9 +103,14 @@ public class BCRSAPrivateKey
return "PKCS#8";
}
+ RSAKeyParameters engineGetKeyParameters()
+ {
+ return rsaPrivateKey;
+ }
+
public byte[] getEncoded()
{
- return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new org.bouncycastle.asn1.pkcs.RSAPrivateKey(getModulus(), ZERO, getPrivateExponent(), ZERO, ZERO, ZERO, ZERO, ZERO));
+ return KeyUtil.getEncodedPrivateKeyInfo(algorithmIdentifier, new org.bouncycastle.asn1.pkcs.RSAPrivateKey(getModulus(), ZERO, getPrivateExponent(), ZERO, ZERO, ZERO, ZERO, ZERO));
}
public boolean equals(Object o)
@@ -134,7 +160,15 @@ public class BCRSAPrivateKey
{
in.defaultReadObject();
+ if (algorithmIdentifierEnc == null)
+ {
+ algorithmIdentifierEnc = getEncoding(BCRSAPublicKey.DEFAULT_ALGORITHM_IDENTIFIER);
+ }
+
+ this.algorithmIdentifier = AlgorithmIdentifier.getInstance(algorithmIdentifierEnc);
+
this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
+ this.rsaPrivateKey = new RSAKeyParameters(true, modulus, privateExponent);
}
private void writeObject(
@@ -155,4 +189,16 @@ public class BCRSAPrivateKey
return buf.toString();
}
+
+ private static byte[] getEncoding(AlgorithmIdentifier algorithmIdentifier)
+ {
+ try
+ {
+ return algorithmIdentifier.getEncoded();
+ }
+ catch (IOException e)
+ {
+ return null;
+ }
+ }
}