public class SM2 extends AbstractAsymmetricCrypto<SM2>
Modifier and Type | Field and Description |
---|---|
protected org.bouncycastle.crypto.engines.SM2Engine |
engine |
protected org.bouncycastle.crypto.signers.SM2Signer |
signer |
algorithm, lock, privateKey, publicKey
Constructor and Description |
---|
SM2()
构造,生成新的私钥公钥对
|
SM2(byte[] privateKey,
byte[] publicKey)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
SM2(byte[] privateKey,
byte[] publicKeyPointX,
byte[] publicKeyPointY)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
SM2(org.bouncycastle.crypto.params.ECPrivateKeyParameters privateKeyParams,
org.bouncycastle.crypto.params.ECPublicKeyParameters publicKeyParams)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
SM2(PrivateKey privateKey,
PublicKey publicKey)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
SM2(String privateKeyStr,
String publicKeyStr)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
SM2(String privateKeyHex,
String publicKeyPointXHex,
String publicKeyPointYHex)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
Modifier and Type | Method and Description |
---|---|
byte[] |
decrypt(byte[] data,
org.bouncycastle.crypto.CipherParameters privateKeyParameters)
解密
|
byte[] |
decrypt(byte[] data,
KeyType keyType)
解密
|
byte[] |
encrypt(byte[] data,
org.bouncycastle.crypto.CipherParameters pubKeyParameters)
加密,SM2非对称加密的结果由C1,C2,C3三部分组成,其中:
|
byte[] |
encrypt(byte[] data,
KeyType keyType)
加密,SM2非对称加密的结果由C1,C2,C3三部分组成,其中:
|
byte[] |
getD()
获得私钥D值(编码后的私钥)
|
byte[] |
getQ(boolean isCompressed)
获得公钥Q值(编码后的公钥)
|
SM2 |
init()
初始化
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密(签名)或者解密(校验) |
SM2 |
initKeys()
生成公钥和私钥
|
SM2 |
setDigest(org.bouncycastle.crypto.Digest digest)
设置Hash算法
|
SM2 |
setEncoding(org.bouncycastle.crypto.signers.DSAEncoding encoding)
设置DSA signatures的编码
|
SM2 |
setMode(org.bouncycastle.crypto.engines.SM2Engine.Mode mode)
设置SM2模式,旧版是C1C2C3,新版本是C1C3C2
|
SM2 |
setPrivateKey(PrivateKey privateKey)
设置私钥
|
SM2 |
setPrivateKeyParams(org.bouncycastle.crypto.params.ECPrivateKeyParameters privateKeyParams)
设置私钥参数
|
SM2 |
setPublicKey(PublicKey publicKey)
设置公钥
|
SM2 |
setPublicKeyParams(org.bouncycastle.crypto.params.ECPublicKeyParameters publicKeyParams)
设置公钥参数
|
byte[] |
sign(byte[] data)
用私钥对信息生成数字签名,签名格式为ASN1
* 在硬件签名中,返回结果为R+S,可以通过调用 SmUtil.rsAsn1ToPlain(byte[]) 方法转换之。 |
byte[] |
sign(byte[] data,
byte[] id)
用私钥对信息生成数字签名,签名格式为ASN1
在硬件签名中,返回结果为R+S,可以通过调用 SmUtil.rsAsn1ToPlain(byte[]) 方法转换之。 |
String |
signHex(String dataHex)
用私钥对信息生成数字签名
|
String |
signHex(String dataHex,
String idHex)
用私钥对信息生成数字签名
|
SM2 |
usePlainEncoding()
设置DSA signatures的编码为PlainDSAEncoding
|
boolean |
verify(byte[] data,
byte[] sign)
用公钥检验数字签名的合法性
|
boolean |
verify(byte[] data,
byte[] sign,
byte[] id)
用公钥检验数字签名的合法性
|
boolean |
verifyHex(String dataHex,
String signHex)
用公钥检验数字签名的合法性
|
boolean |
verifyHex(String dataHex,
String signHex,
String idHex)
用公钥检验数字签名的合法性
|
decrypt, decrypt, decryptFromBcd, decryptFromBcd, decryptStr, decryptStr, decryptStrFromBcd, decryptStrFromBcd, encrypt, encrypt, encrypt, encrypt, encryptBase64, encryptBase64, encryptBase64, encryptBase64, encryptBcd, encryptBcd, encryptHex, encryptHex, encryptHex, encryptHex
getKeyByType, getPrivateKey, getPrivateKeyBase64, getPublicKey, getPublicKeyBase64, init, setKey
protected org.bouncycastle.crypto.engines.SM2Engine engine
protected org.bouncycastle.crypto.signers.SM2Signer signer
public SM2()
public SM2(String privateKeyStr, String publicKeyStr)
privateKeyStr
- 私钥Hex或Base64表示,必须使用PKCS#8规范publicKeyStr
- 公钥Hex或Base64表示,必须使用X509规范public SM2(byte[] privateKey, byte[] publicKey)
privateKey
- 私钥,可以使用PKCS#8、D值或PKCS#1规范publicKey
- 公钥,可以使用X509、Q值或PKCS#1规范public SM2(PrivateKey privateKey, PublicKey publicKey)
privateKey
- 私钥publicKey
- 公钥public SM2(String privateKeyHex, String publicKeyPointXHex, String publicKeyPointYHex)
privateKeyHex
- 私钥16进制publicKeyPointXHex
- 公钥X16进制publicKeyPointYHex
- 公钥Y16进制public SM2(byte[] privateKey, byte[] publicKeyPointX, byte[] publicKeyPointY)
privateKey
- 私钥publicKeyPointX
- 公钥XpublicKeyPointY
- 公钥Ypublic SM2(org.bouncycastle.crypto.params.ECPrivateKeyParameters privateKeyParams, org.bouncycastle.crypto.params.ECPublicKeyParameters publicKeyParams)
privateKeyParams
- 私钥,可以为nullpublicKeyParams
- 公钥,可以为nullpublic SM2 init()
public SM2 initKeys()
BaseAsymmetric
initKeys
in class BaseAsymmetric<SM2>
public byte[] encrypt(byte[] data, KeyType keyType) throws CryptoException
C1 生成随机数的计算出的椭圆曲线点 C2 密文数据 C3 SM3的摘要值
encrypt
in class AbstractAsymmetricCrypto<SM2>
data
- 被加密的byteskeyType
- 私钥或公钥 KeyType
CryptoException
- 包括InvalidKeyException和InvalidCipherTextException的包装异常public byte[] encrypt(byte[] data, org.bouncycastle.crypto.CipherParameters pubKeyParameters) throws CryptoException
C1 生成随机数的计算出的椭圆曲线点 C2 密文数据 C3 SM3的摘要值
data
- 被加密的bytespubKeyParameters
- 公钥参数CryptoException
- 包括InvalidKeyException和InvalidCipherTextException的包装异常public byte[] decrypt(byte[] data, KeyType keyType) throws CryptoException
decrypt
in class AbstractAsymmetricCrypto<SM2>
data
- SM2密文,实际包含三部分:ECC公钥、真正的密文、公钥和原文的SM3-HASH值keyType
- 私钥或公钥 KeyType
CryptoException
- 包括InvalidKeyException和InvalidCipherTextException的包装异常public byte[] decrypt(byte[] data, org.bouncycastle.crypto.CipherParameters privateKeyParameters) throws CryptoException
data
- SM2密文,实际包含三部分:ECC公钥、真正的密文、公钥和原文的SM3-HASH值privateKeyParameters
- 私钥参数CryptoException
- 包括InvalidKeyException和InvalidCipherTextException的包装异常public String signHex(String dataHex)
dataHex
- 被签名的数据数据public byte[] sign(byte[] data)
SmUtil.rsAsn1ToPlain(byte[])
方法转换之。data
- 加密数据public String signHex(String dataHex, String idHex)
dataHex
- 被签名的数据数据idHex
- 可以为null,若为null,则默认withId为字节数组:"1234567812345678".getBytes()public byte[] sign(byte[] data, byte[] id)
SmUtil.rsAsn1ToPlain(byte[])
方法转换之。data
- 被签名的数据数据id
- 可以为null,若为null,则默认withId为字节数组:"1234567812345678".getBytes()public boolean verifyHex(String dataHex, String signHex)
dataHex
- 数据签名后的数据signHex
- 签名public boolean verify(byte[] data, byte[] sign)
data
- 签名后的数据sign
- 签名public boolean verifyHex(String dataHex, String signHex, String idHex)
dataHex
- 数据签名后的数据的Hex值signHex
- 签名的Hex值idHex
- ID的Hex值public boolean verify(byte[] data, byte[] sign, byte[] id)
data
- 数据签名后的数据sign
- 签名id
- 可以为null,若为null,则默认withId为字节数组:"1234567812345678".getBytes()public SM2 setPrivateKey(PrivateKey privateKey)
BaseAsymmetric
setPrivateKey
in class BaseAsymmetric<SM2>
privateKey
- 私钥public SM2 setPrivateKeyParams(org.bouncycastle.crypto.params.ECPrivateKeyParameters privateKeyParams)
privateKeyParams
- 私钥参数public SM2 setPublicKey(PublicKey publicKey)
BaseAsymmetric
setPublicKey
in class BaseAsymmetric<SM2>
publicKey
- 公钥public SM2 setPublicKeyParams(org.bouncycastle.crypto.params.ECPublicKeyParameters publicKeyParams)
publicKeyParams
- 公钥参数public SM2 usePlainEncoding()
public SM2 setEncoding(org.bouncycastle.crypto.signers.DSAEncoding encoding)
encoding
- DSAEncoding
实现public SM2 setDigest(org.bouncycastle.crypto.Digest digest)
digest
- Digest
实现public SM2 setMode(org.bouncycastle.crypto.engines.SM2Engine.Mode mode)
mode
- SM2Engine.Mode
public byte[] getD()
public byte[] getQ(boolean isCompressed)
isCompressed
- 是否压缩Copyright © 2021. All rights reserved.