55*/
66package com .peersafe .base .crypto ;
77
8- import sun .security .util .CurveDB ;
8+ // import sun.security.util.CurveDB;
9+ // import sun.security.ec.CurveDB;
910import sun .security .util .ObjectIdentifier ;
1011import sun .security .x509 .AlgorithmId ;
1112
@@ -26,8 +27,22 @@ public class X509CryptoSuite {
2627 private static final String CIPHER_GM = "ECDHE-SM2-WITH-SMS4-GCM-SM3" ;
2728
2829 public static void enableX509CertificateWithGM () throws IllegalAccessException , InvocationTargetException ,
29- NoSuchFieldException , ClassNotFoundException {
30- Method [] methods = CurveDB .class .getDeclaredMethods ();
30+ NoSuchFieldException , ClassNotFoundException ,Exception {
31+
32+ final String javaVer = System .getProperty ("java.version" );
33+ if (!javaVer .contains ("1.8.0" )) {
34+ throw new RuntimeException ("jdk version don't support" );
35+ }
36+ int javaVersion = Integer .parseInt (javaVer .substring (javaVer .length ()-3 , javaVer .length ()));
37+ ClassLoader classLoader = X509CryptoSuite .class .getClassLoader ();
38+ Class CurveDB ;
39+ if (javaVersion < 292 ){
40+ CurveDB = classLoader .loadClass ("sun.security.ec.CurveDB" );
41+ } else {
42+ CurveDB = classLoader .loadClass ("sun.security.util.CurveDB" );
43+ }
44+ // Method[] methods = CurveDB.class.getDeclaredMethods();
45+ Method [] methods = CurveDB .getDeclaredMethods ();
3146 Method method = null ;
3247 Method getNamesByOID = null ;
3348 boolean notSeted = true ;
@@ -43,7 +58,8 @@ public static void enableX509CertificateWithGM() throws IllegalAccessException,
4358 }
4459 if (getNamesByOID != null ) {
4560 getNamesByOID .setAccessible (true );
46- String [] nameArray = (String [])getNamesByOID .invoke (CurveDB .class , "1.2.156.10197.1.301" );
61+ // String[] nameArray = (String [])getNamesByOID.invoke(CurveDB.class, "1.2.156.10197.1.301");
62+ String [] nameArray = (String [])getNamesByOID .invoke (CurveDB , "1.2.156.10197.1.301" );
4763 if (nameArray .length != 0 )
4864 {
4965 notSeted = false ;
@@ -56,7 +72,8 @@ public static void enableX509CertificateWithGM() throws IllegalAccessException,
5672 throw new NoSuchFieldException ();
5773 }
5874 method .setAccessible (true );
59- method .invoke (CurveDB .class , "sm2p256v1" , "1.2.156.10197.1.301" , 1 ,
75+ // method.invoke(CurveDB.class, "sm2p256v1", "1.2.156.10197.1.301", 1,
76+ method .invoke (CurveDB , "sm2p256v1" , "1.2.156.10197.1.301" , 1 ,
6077 "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF" ,
6178 "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC" ,
6279 "28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93" ,
@@ -65,11 +82,14 @@ public static void enableX509CertificateWithGM() throws IllegalAccessException,
6582 "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123" ,
6683 1 , splitPattern );
6784
68- final Field specCollection = CurveDB .class .getDeclaredField ("specCollection" );
69- final Field oidMap = CurveDB .class .getDeclaredField ("oidMap" );
85+ // final Field specCollection = CurveDB.class.getDeclaredField("specCollection");
86+ final Field specCollection = CurveDB .getDeclaredField ("specCollection" );
87+ // final Field oidMap = CurveDB.class.getDeclaredField("oidMap");
88+ final Field oidMap = CurveDB .getDeclaredField ("oidMap" );
7089 oidMap .setAccessible (true );
7190 specCollection .setAccessible (true );
72- specCollection .set (CurveDB .class , Collections .unmodifiableCollection (((Map ) oidMap .get (CurveDB .class )).values ()));
91+ // specCollection.set(CurveDB.class, Collections.unmodifiableCollection(((Map) oidMap.get(CurveDB.class)).values()));
92+ specCollection .set (CurveDB , Collections .unmodifiableCollection (((Map ) oidMap .get (CurveDB )).values ()));
7393
7494 Field nameTable = AlgorithmId .class .getDeclaredField ("nameTable" );
7595 nameTable .setAccessible (true );
0 commit comments