public class Sm2Utils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static org.bouncycastle.math.ec.custom.gm.SM2P256V1Curve |
CURVE |
static int |
CURVE_LEN |
static org.bouncycastle.crypto.params.ECDomainParameters |
DOMAIN_PARAMS |
static org.bouncycastle.math.ec.ECPoint |
G_POINT |
static BigInteger |
SM2_ECC_GX |
static BigInteger |
SM2_ECC_GY |
static BigInteger |
SM2_ECC_H |
static BigInteger |
SM2_ECC_N |
| 构造器和说明 |
|---|
Sm2Utils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static byte[] |
decrypt(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey priKey,
byte[] sm2Cipher) |
static byte[] |
decrypt(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
org.bouncycastle.crypto.params.ECPrivateKeyParameters priKeyParameters,
byte[] sm2Cipher) |
static byte[] |
encodeSM2SignToDER(byte[] rawSign)
把64字节的纯R+S字节数组编码成DER编码
|
static byte[] |
encrypt(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey pubKey,
byte[] srcData) |
static byte[] |
encrypt(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
org.bouncycastle.crypto.params.ECPublicKeyParameters pubKeyParameters,
byte[] srcData) |
static KeyPair |
generateKeyPair()
生成密钥对
|
static int |
getCurveLength(org.bouncycastle.crypto.params.ECDomainParameters domainParams) |
static byte[] |
getRawPrivateKey(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey privateKey)
只获取私钥里的d值,32字节
|
static byte[] |
getRawPublicKey(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey publicKey)
只获取公钥里的XY分量,64字节
|
static String |
key2String(Key key)
密钥对象转换成string
|
static byte[] |
sign(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey priKey,
byte[] srcData)
签名
|
static byte[] |
sign(org.bouncycastle.crypto.params.ECPrivateKeyParameters priKeyParameters,
byte[] withId,
byte[] srcData)
签名
|
static String |
sign(String data,
org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey priKey)
sm2密钥进行签名
|
static String |
sign(String data,
org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey priKey,
com.yeepay.yop.sdk.auth.SignOptions options)
sm2密钥进行签名
|
static PrivateKey |
string2PrivateKey(String priKey)
string类型的私钥转换后私钥对象
|
static PublicKey |
string2PublicKey(String pubKey)
string类型的公钥转换成公钥对象
|
static boolean |
verify(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey pubKey,
byte[] srcData,
byte[] sign)
验签
|
static boolean |
verify(org.bouncycastle.crypto.params.ECPublicKeyParameters pubKeyParameters,
byte[] withId,
byte[] srcData,
byte[] sign)
验签
|
static boolean |
verifySign(String data,
String signature,
org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey publicKey)
sm2密钥进行签名验证
|
public static final org.bouncycastle.math.ec.custom.gm.SM2P256V1Curve CURVE
public static final BigInteger SM2_ECC_N
public static final BigInteger SM2_ECC_H
public static final BigInteger SM2_ECC_GX
public static final BigInteger SM2_ECC_GY
public static final org.bouncycastle.math.ec.ECPoint G_POINT
public static final org.bouncycastle.crypto.params.ECDomainParameters DOMAIN_PARAMS
public static final int CURVE_LEN
public static KeyPair generateKeyPair()
public static PublicKey string2PublicKey(String pubKey)
pubKey - NoSuchAlgorithmExceptionInvalidKeySpecExceptionNoSuchProviderExceptionpublic static PrivateKey string2PrivateKey(String priKey)
priKey - NoSuchAlgorithmExceptionInvalidKeySpecExceptionNoSuchProviderExceptionpublic static String sign(String data, org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey priKey)
data - priKey - public static String sign(String data, org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey priKey, com.yeepay.yop.sdk.auth.SignOptions options)
data - priKey - options - public static boolean verifySign(String data, String signature, org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey publicKey)
data - signature - publicKey - public static byte[] encodeSM2SignToDER(byte[] rawSign)
throws IOException
rawSign - 64字节数组形式的SM2签名值,前32字节为R,后32字节为SIOExceptionpublic static byte[] sign(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey priKey,
byte[] srcData)
throws org.bouncycastle.crypto.CryptoException
priKey - 私钥srcData - 原文org.bouncycastle.crypto.CryptoExceptionpublic static byte[] sign(org.bouncycastle.crypto.params.ECPrivateKeyParameters priKeyParameters,
byte[] withId,
byte[] srcData)
throws org.bouncycastle.crypto.CryptoException
priKeyParameters - 私钥withId - 可以为null,若为null,则默认withId为字节数组:"1234567812345678".getBytes()srcData - 源数据org.bouncycastle.crypto.CryptoExceptionpublic static boolean verify(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey pubKey,
byte[] srcData,
byte[] sign)
pubKey - 公钥srcData - 原文sign - DER编码的签名值public static boolean verify(org.bouncycastle.crypto.params.ECPublicKeyParameters pubKeyParameters,
byte[] withId,
byte[] srcData,
byte[] sign)
pubKeyParameters - 公钥withId - 可以为null,若为null,则默认withId为字节数组:"1234567812345678".getBytes()srcData - 原文sign - DER编码的签名值public static byte[] encrypt(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey pubKey,
byte[] srcData)
throws org.bouncycastle.crypto.InvalidCipherTextException
pubKey - 公钥srcData - 原文org.bouncycastle.crypto.InvalidCipherTextExceptionpublic static byte[] encrypt(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
org.bouncycastle.crypto.params.ECPublicKeyParameters pubKeyParameters,
byte[] srcData)
throws org.bouncycastle.crypto.InvalidCipherTextException
mode - 指定密文结构,旧标准的为C1C2C3,新的[《SM2密码算法使用规范》 GM/T 0009-2012]标准为C1C3C2pubKeyParameters - 公钥srcData - 原文org.bouncycastle.crypto.InvalidCipherTextExceptionpublic static byte[] decrypt(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey priKey,
byte[] sm2Cipher)
throws org.bouncycastle.crypto.InvalidCipherTextException
priKey - 私钥sm2Cipher - 默认输入C1C3C2顺序的密文。C1为65字节第1字节为压缩标识,这里固定为0x04,后面64字节为xy分量各32字节。C3为32字节。C2长度与原文一致。org.bouncycastle.crypto.InvalidCipherTextExceptionpublic static byte[] decrypt(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
org.bouncycastle.crypto.params.ECPrivateKeyParameters priKeyParameters,
byte[] sm2Cipher)
throws org.bouncycastle.crypto.InvalidCipherTextException
mode - 指定密文结构,旧标准的为C1C2C3,新的[《SM2密码算法使用规范》 GM/T 0009-2012]标准为C1C3C2priKeyParameters - 私钥sm2Cipher - 根据mode不同,需要输入的密文C1C2C3排列顺序不同。C1为65字节第1字节为压缩标识,这里固定为0x04,后面64字节为xy分量各32字节。C3为32字节。C2长度与原文一致。org.bouncycastle.crypto.InvalidCipherTextExceptionpublic static byte[] getRawPrivateKey(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey privateKey)
privateKey - public static byte[] getRawPublicKey(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey publicKey)
publicKey - public static int getCurveLength(org.bouncycastle.crypto.params.ECDomainParameters domainParams)
Copyright © 2024. All rights reserved.