Skip to content

Commit

Permalink
[MOD]升级BC版本到1.64
Browse files Browse the repository at this point in the history
[ADD]兼容旧标准C1C2C3结构/新标准C1C3C2结构的SM2密文,默认为新标准C1C3C2结构
  • Loading branch information
ZZMarquis committed Jan 19, 2020
1 parent 7accfe7 commit cf651d4
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 61 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.62</version>
<version>1.64</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/zz/gmhelper/BCECUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.asn1.x9.X962Parameters;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.asn1.x9.X9ECPoint;
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.generators.ECKeyPairGenerator;
Expand Down Expand Up @@ -404,12 +405,22 @@ public static X962Parameters getDomainParametersFromName(java.security.spec.ECPa
} else {
ECCurve curve = EC5Util.convertCurve(ecSpec.getCurve());

X9ECParameters ecP = new X9ECParameters(
curve,
new X9ECPoint(EC5Util.convertPoint(curve, ecSpec.getGenerator()), withCompression),
ecSpec.getOrder(),
BigInteger.valueOf(ecSpec.getCofactor()),
ecSpec.getCurve().getSeed());

//// 如果是1.62或更低版本的bcprov-jdk15on应该使用以下这段代码,因为高版本的EC5Util.convertPoint没有向下兼容
/*
X9ECParameters ecP = new X9ECParameters(
curve,
EC5Util.convertPoint(curve, ecSpec.getGenerator(), withCompression),
ecSpec.getOrder(),
BigInteger.valueOf(ecSpec.getCofactor()),
ecSpec.getCurve().getSeed());
*/

params = new X962Parameters(ecP);
}
Expand Down
Loading

0 comments on commit cf651d4

Please sign in to comment.