Maven依赖
<dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcprov-jdk15on</artifactId> <version>1.57</version> </dependency>
实体类代码
package com.code.gen;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class SM2KeyPair {
/** 公钥 */
private String publicKey;
/** 私钥 */
private String privateKey;
}
工具类代码
package com.code.gen.util;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Base64;
import com.code.gen.SM2KeyPair;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.bouncycastle.asn1.gm.GMNamedCurves;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.asn1.x9.X9ECPoint;
import org.bouncycastle.c