SM2 java代码的实现。
public class SM2 {
//正式参数
public static String[] ecc_param = {
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF",
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC",
"28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93",
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123",
"32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7",
"BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0"
};
private static SM2 instance;
private BigInteger ecc_p;
private BigInteger ecc_a;
private BigInteger ecc_b;
private BigInteger ecc_n;
private BigInteger ecc_gx;
private BigInteger ecc_gy;
private ECCurve.Fp ecc_curve;
private ECPoint.Fp ecc_point_g;
private ECDomainParameters ecc_bc_spec;
private ECKeyPairGenerator ecc_key_pair_generator;
private ECFieldElement ecc_gx_fieldelement;
private ECFieldElement ecc_gy_fieldelement;
private BigInteger privateKey;
private ECPoint publicKey;
private SM2() {
this.ecc_p = new BigInteger(ecc_param[0], 16);
this.ecc_a = new BigInteger(ecc_param[1], 16);
this.ecc_b = new BigInteger(ecc_param[2], 16);
this.ecc_n = new BigInteger(ecc_param[3], 16);
this.ecc_gx = new BigInteger(ecc_param[4], 16);
this.ecc_gy = new BigInteger(ecc_param[5], 16);
ecc_gx_fieldelement = new Fp(this.ecc_p, this.ecc_gx);
ecc_gy_fieldelement = new Fp(this.ecc_p, this.ecc_gy);
ecc_curve = new ECCurve.Fp(this.ecc_p, this.ecc_a, this.ecc_b);
ecc_point_g = new ECPoint.Fp(this.ecc_curve, this.ecc_gx_fieldelement, this.ecc_gy_fieldelement);