public class SM2Util extends GMBaseUtil
| 限定符和类型 | 字段和说明 |
|---|---|
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 EllipticCurve |
JDK_CURVE |
static ECParameterSpec |
JDK_EC_SPEC |
static ECPoint |
JDK_G_POINT |
static BigInteger |
SM2_ECC_A |
static BigInteger |
SM2_ECC_B |
static BigInteger |
SM2_ECC_GX |
static BigInteger |
SM2_ECC_GY |
static BigInteger |
SM2_ECC_H |
static BigInteger |
SM2_ECC_N |
static BigInteger |
SM2_ECC_P |
static int |
SM3_DIGEST_LENGTH |
| 构造器和说明 |
|---|
SM2Util() |
| 限定符和类型 | 方法和说明 |
|---|---|
static byte[] |
decodeDERSM2Cipher(byte[] derCipher)
解码DER密文
|
static byte[] |
decodeDERSM2Cipher(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
byte[] derCipher) |
static byte[] |
decodeDERSM2Sign(byte[] derSign)
将DER编码的SM2签名解码成64字节的纯R+S字节流
|
static byte[] |
decrypt(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey priKey,
byte[] sm2Cipher) |
static byte[] |
decrypt(byte[] privBytes,
byte[] cipherDataDer) |
static byte[] |
decrypt(org.bouncycastle.crypto.params.ECPrivateKeyParameters priKeyParameters,
byte[] sm2Cipher) |
static byte[] |
decrypt(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
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[] |
encodeSM2CipherToDER(byte[] cipher)
DER编码密文
|
static byte[] |
encodeSM2CipherToDER(int curveLength,
int digestLength,
byte[] cipher)
DER编码密文
|
static byte[] |
encodeSM2CipherToDER(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
byte[] cipher)
DER编码密文
|
static byte[] |
encodeSM2CipherToDER(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
int curveLength,
int digestLength,
byte[] cipher) |
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(byte[] pubBytes,
byte[] srcData) |
static byte[] |
encrypt(org.bouncycastle.crypto.params.ECPublicKeyParameters pubKeyParameters,
byte[] srcData) |
static byte[] |
encrypt(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
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()
生成ECC密钥对
|
static org.bouncycastle.crypto.AsymmetricCipherKeyPair |
generateKeyPairParameter()
生成ECC密钥对
|
static org.bouncycastle.crypto.AsymmetricCipherKeyPair |
generateKeyPairParameter(byte[] seed)
通过seed 生成ECC密钥对
|
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 SM2Cipher |
parseSM2Cipher(byte[] cipherText)
分解SM2密文
|
static SM2Cipher |
parseSM2Cipher(int curveLength,
int digestLength,
byte[] cipherText) |
static SM2Cipher |
parseSM2Cipher(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
byte[] cipherText)
分解SM2密文
|
static SM2Cipher |
parseSM2Cipher(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
int curveLength,
int digestLength,
byte[] cipherText)
分解SM2密文
|
static byte[] |
sign(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey priKey,
byte[] srcData)
签名
|
static byte[] |
sign(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey priKey,
byte[] withId,
byte[] srcData)
私钥签名
|
static byte[] |
sign(org.bouncycastle.crypto.params.ECPrivateKeyParameters priKeyParameters,
byte[] srcData)
签名
|
static byte[] |
sign(org.bouncycastle.crypto.params.ECPrivateKeyParameters priKeyParameters,
byte[] withId,
byte[] srcData)
签名
|
static boolean |
verify(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey pubKey,
byte[] srcData,
byte[] sign)
验签
|
static boolean |
verify(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey pubKey,
byte[] withId,
byte[] srcData,
byte[] sign)
验签
|
static boolean |
verify(org.bouncycastle.crypto.params.ECPublicKeyParameters pubKeyParameters,
byte[] srcData,
byte[] sign)
验签
不指定withId,则默认withId为字节数组:"1234567812345678".getBytes()
|
static boolean |
verify(org.bouncycastle.crypto.params.ECPublicKeyParameters pubKeyParameters,
byte[] withId,
byte[] srcData,
byte[] sign)
验签
|
public static final org.bouncycastle.math.ec.custom.gm.SM2P256V1Curve CURVE
public static final BigInteger SM2_ECC_P
public static final BigInteger SM2_ECC_A
public static final BigInteger SM2_ECC_B
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 final EllipticCurve JDK_CURVE
public static final ECPoint JDK_G_POINT
public static final ECParameterSpec JDK_EC_SPEC
public static final int SM3_DIGEST_LENGTH
public static org.bouncycastle.crypto.AsymmetricCipherKeyPair generateKeyPairParameter(byte[] seed)
seed - public static org.bouncycastle.crypto.AsymmetricCipherKeyPair generateKeyPairParameter()
public static KeyPair generateKeyPair() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException
public 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 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.jcajce.provider.asymmetric.ec.BCECPublicKey pubKey,
byte[] srcData)
throws org.bouncycastle.crypto.InvalidCipherTextException
mode - 指定密文结构,旧标准的为C1C2C3,新的[《SM2密码算法使用规范》 GM/T 0009-2012]标准为C1C3C2pubKey - 公钥srcData - 原文org.bouncycastle.crypto.InvalidCipherTextExceptionpublic static byte[] encrypt(org.bouncycastle.crypto.params.ECPublicKeyParameters pubKeyParameters,
byte[] srcData)
throws org.bouncycastle.crypto.InvalidCipherTextException
pubKeyParameters - 公钥srcData - 原文org.bouncycastle.crypto.InvalidCipherTextExceptionpublic static byte[] encrypt(byte[] pubBytes,
byte[] srcData)
throws org.bouncycastle.crypto.InvalidCipherTextException
pubBytes - 公钥srcData - 原文org.bouncycastle.crypto.InvalidCipherTextExceptionpublic static byte[] decrypt(byte[] privBytes,
byte[] cipherDataDer)
throws org.bouncycastle.crypto.InvalidCipherTextException
privBytes - 私钥cipherData - 密文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.jcajce.provider.asymmetric.ec.BCECPrivateKey priKey,
byte[] sm2Cipher)
throws org.bouncycastle.crypto.InvalidCipherTextException
mode - 指定密文结构,旧标准的为C1C2C3,新的[《SM2密码算法使用规范》 GM/T 0009-2012]标准为C1C3C2priKey - 私钥sm2Cipher - 根据mode不同,需要输入的密文C1C2C3排列顺序不同。C1为65字节第1字节为压缩标识,这里固定为0x04,后面64字节为xy分量各32字节。C3为32字节。C2长度与原文一致。org.bouncycastle.crypto.InvalidCipherTextExceptionpublic static byte[] decrypt(org.bouncycastle.crypto.params.ECPrivateKeyParameters priKeyParameters,
byte[] sm2Cipher)
throws org.bouncycastle.crypto.InvalidCipherTextException
priKeyParameters - 私钥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 SM2Cipher parseSM2Cipher(byte[] cipherText) throws Exception
cipherText - 默认输入C1C3C2顺序的密文。C1为65字节第1字节为压缩标识,这里固定为0x04,后面64字节为xy分量各32字节。C3为32字节。C2长度与原文一致。Exceptionpublic static SM2Cipher parseSM2Cipher(org.bouncycastle.crypto.engines.SM2Engine.Mode mode, byte[] cipherText) throws Exception
mode - 指定密文结构,旧标准的为C1C2C3,新的[《SM2密码算法使用规范》 GM/T 0009-2012]标准为C1C3C2cipherText - 根据mode不同,需要输入的密文C1C2C3排列顺序不同。C1为65字节第1字节为压缩标识,这里固定为0x04,后面64字节为xy分量各32字节。C3为32字节。C2长度与原文一致。Exceptionpublic static SM2Cipher parseSM2Cipher(int curveLength, int digestLength, byte[] cipherText) throws Exception
curveLength - 曲线长度,SM2的话就是256位。digestLength - 摘要长度,如果是SM2的话因为默认使用SM3摘要,SM3摘要长度为32字节。cipherText - 默认输入C1C3C2顺序的密文。C1为65字节第1字节为压缩标识,这里固定为0x04,后面64字节为xy分量各32字节。C3为32字节。C2长度与原文一致。Exceptionpublic static SM2Cipher parseSM2Cipher(org.bouncycastle.crypto.engines.SM2Engine.Mode mode, int curveLength, int digestLength, byte[] cipherText) throws Exception
mode - 指定密文结构,旧标准的为C1C2C3,新的[《SM2密码算法使用规范》 GM/T 0009-2012]标准为C1C3C2curveLength - 曲线长度,SM2的话就是256位。digestLength - 摘要长度,如果是SM2的话因为默认使用SM3摘要,SM3摘要长度为32字节。cipherText - 根据mode不同,需要输入的密文C1C2C3排列顺序不同。C1为65字节第1字节为压缩标识,这里固定为0x04,后面64字节为xy分量各32字节。C3为32字节。C2长度与原文一致。Exceptionpublic static byte[] encodeSM2CipherToDER(byte[] cipher)
throws Exception
cipher - 默认输入C1C3C2顺序的密文。C1为65字节第1字节为压缩标识,这里固定为0x04,后面64字节为xy分量各32字节。C3为32字节。C2长度与原文一致。IOExceptionExceptionpublic static byte[] encodeSM2CipherToDER(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
byte[] cipher)
throws Exception
mode - 指定密文结构,旧标准的为C1C2C3,新的[《SM2密码算法使用规范》 GM/T 0009-2012]标准为C1C3C2cipher - 根据mode不同,需要输入的密文C1C2C3排列顺序不同。C1为65字节第1字节为压缩标识,这里固定为0x04,后面64字节为xy分量各32字节。C3为32字节。C2长度与原文一致。Exceptionpublic static byte[] encodeSM2CipherToDER(int curveLength,
int digestLength,
byte[] cipher)
throws Exception
curveLength - 曲线长度,SM2的话就是256位。digestLength - 摘要长度,如果是SM2的话因为默认使用SM3摘要,SM3摘要长度为32字节。cipher - 默认输入C1C3C2顺序的密文。C1为65字节第1字节为压缩标识,这里固定为0x04,后面64字节为xy分量各32字节。C3为32字节。C2长度与原文一致。IOExceptionExceptionpublic static byte[] encodeSM2CipherToDER(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
int curveLength,
int digestLength,
byte[] cipher)
throws Exception
mode - 指定密文结构,旧标准的为C1C2C3,新的[《SM2密码算法使用规范》 GM/T 0009-2012]标准为C1C3C2curveLength - 曲线长度,SM2的话就是256位。digestLength - 摘要长度,如果是SM2的话因为默认使用SM3摘要,SM3摘要长度为32字节。cipher - 根据mode不同,需要输入的密文C1C2C3排列顺序不同。C1为65字节第1字节为压缩标识,这里固定为0x04,后面64字节为xy分量各32字节。C3为32字节。C2长度与原文一致。Exceptionpublic static byte[] decodeDERSM2Cipher(byte[] derCipher)
throws Exception
derCipher - 默认输入按C1C3C2顺序DER编码的密文Exceptionpublic static byte[] decodeDERSM2Cipher(org.bouncycastle.crypto.engines.SM2Engine.Mode mode,
byte[] derCipher)
throws Exception
mode - 指定密文结构,旧标准的为C1C2C3,新的[《SM2密码算法使用规范》 GM/T 0009-2012]标准为C1C3C2derCipher - 根据mode输入C1C2C3或C1C3C2顺序DER编码后的密文Exceptionpublic 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[] srcData)
throws org.bouncycastle.crypto.CryptoException
priKeyParameters - 私钥srcData - 原文org.bouncycastle.crypto.CryptoExceptionpublic static byte[] sign(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey priKey,
byte[] withId,
byte[] srcData)
throws org.bouncycastle.crypto.CryptoException
priKey - 私钥withId - 可以为null,若为null,则默认withId为字节数组:"1234567812345678".getBytes()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,srcData - 源数据org.bouncycastle.crypto.CryptoExceptionpublic static byte[] decodeDERSM2Sign(byte[] derSign)
derSign - public static byte[] encodeSM2SignToDER(byte[] rawSign)
throws IOException
rawSign - 64字节数组形式的SM2签名值,前32字节为R,后32字节为SIOExceptionpublic 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[] srcData,
byte[] sign)
pubKeyParameters - 公钥srcData - 原文sign - DER编码的签名值public static boolean verify(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey pubKey,
byte[] withId,
byte[] srcData,
byte[] sign)
pubKey - 公钥withId - 可以为null,若为null,则默认withId为字节数组:"1234567812345678".getBytes()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编码的签名值Copyright © 2021. All rights reserved.