|
14 | 14 | import org.bouncycastle.asn1.pkcs.RSAPrivateKey; |
15 | 15 | import org.bouncycastle.asn1.sec.ECPrivateKey; |
16 | 16 | import org.bouncycastle.asn1.x9.ECNamedCurveTable; |
| 17 | +import org.bouncycastle.asn1.x9.X962Parameters; |
17 | 18 | import org.bouncycastle.asn1.x9.X9ECParameters; |
18 | 19 | import org.bouncycastle.crypto.CryptoServicesRegistrar; |
| 20 | +import org.bouncycastle.crypto.ec.CustomNamedCurves; |
19 | 21 | import org.bouncycastle.crypto.params.AsymmetricKeyParameter; |
20 | 22 | import org.bouncycastle.crypto.params.DSAParameters; |
21 | 23 | import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; |
| 24 | +import org.bouncycastle.crypto.params.ECDomainParameters; |
22 | 25 | import org.bouncycastle.crypto.params.ECNamedDomainParameters; |
23 | 26 | import org.bouncycastle.crypto.params.ECPrivateKeyParameters; |
24 | 27 | import org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters; |
@@ -199,13 +202,29 @@ else if (sequence.size() == 4) |
199 | 202 | && sequence.getObjectAt(2) instanceof ASN1TaggedObject) |
200 | 203 | { |
201 | 204 | ECPrivateKey ecPrivateKey = ECPrivateKey.getInstance(sequence); |
202 | | - ASN1ObjectIdentifier curveOID = ASN1ObjectIdentifier.getInstance(ecPrivateKey.getParametersObject()); |
203 | | - X9ECParameters x9Params = ECNamedCurveTable.getByOID(curveOID); |
204 | | - result = new ECPrivateKeyParameters( |
205 | | - ecPrivateKey.getKey(), |
206 | | - new ECNamedDomainParameters( |
207 | | - curveOID, |
208 | | - x9Params)); |
| 205 | + |
| 206 | + X962Parameters parameters = X962Parameters.getInstance( |
| 207 | + ecPrivateKey.getParametersObject().toASN1Primitive()); |
| 208 | + ECDomainParameters domainParams; |
| 209 | + if (parameters.isNamedCurve()) |
| 210 | + { |
| 211 | + ASN1ObjectIdentifier oid = ASN1ObjectIdentifier.getInstance(parameters.getParameters()); |
| 212 | + X9ECParameters x9 = CustomNamedCurves.getByOID(oid); |
| 213 | + if (x9 == null) |
| 214 | + { |
| 215 | + x9 = ECNamedCurveTable.getByOID(oid); |
| 216 | + } |
| 217 | + domainParams = new ECNamedDomainParameters(oid, x9); |
| 218 | + } |
| 219 | + else |
| 220 | + { |
| 221 | + X9ECParameters x9 = X9ECParameters.getInstance(parameters.getParameters()); |
| 222 | + domainParams = new ECDomainParameters(x9); |
| 223 | + } |
| 224 | + |
| 225 | + BigInteger d = ecPrivateKey.getKey(); |
| 226 | + |
| 227 | + result = new ECPrivateKeyParameters(d, domainParams); |
209 | 228 | } |
210 | 229 | } |
211 | 230 | } |
|
0 commit comments