public class SM2 extends Object
| 构造器和说明 |
|---|
SM2(byte[] privateKey,
byte[] publicKey) |
SM2(org.bouncycastle.crypto.params.ECPrivateKeyParameters privateKeyParams,
org.bouncycastle.crypto.params.ECPublicKeyParameters publicKeyParams) |
SM2(PrivateKey privateKey,
PublicKey publicKey) |
| 限定符和类型 | 方法和说明 |
|---|---|
byte[] |
decrypt(byte[] data)
使用私钥解密
|
byte[] |
encrypt(byte[] data)
加密,SM2非对称加密的结果由C1,C2,C3三部分组成,其中:
C1 生成随机数的计算出的椭圆曲线点
C2 密文数据
C3 SM3的摘要值
|
byte[] |
getD()
获得私钥D值(编码后的私钥)
|
BigInteger |
getDBigInteger()
获得私钥D值
|
byte[] |
getQ(boolean isCompressed)
获得公钥Q值(编码后的公钥)
|
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
|
byte[] |
sign(byte[] data)
用私钥对信息生成数字签名,签名格式为ASN1
* 在硬件签名中,返回结果为R+S,可以通过调用 SmUtils.rsAsn1ToPlain(byte[])方法转换之。 |
byte[] |
sign(byte[] data,
byte[] id)
用私钥对信息生成数字签名,签名格式为ASN1
在硬件签名中,返回结果为R+S,可以通过调用 SmUtils.rsAsn1ToPlain(byte[])方法转换之。 |
SM2 |
usePlainEncoding()
设置DSA signatures的编码为PlainDSAEncoding
|
boolean |
verify(byte[] data,
byte[] sign)
用公钥检验数字签名的合法性
|
boolean |
verify(byte[] data,
byte[] sign,
byte[] id)
用公钥检验数字签名的合法性
|
public SM2(org.bouncycastle.crypto.params.ECPrivateKeyParameters privateKeyParams,
org.bouncycastle.crypto.params.ECPublicKeyParameters publicKeyParams)
public SM2(PrivateKey privateKey, PublicKey publicKey) throws InvalidKeyException
public SM2(byte[] privateKey,
byte[] publicKey)
throws GeneralSecurityException
public byte[] encrypt(byte[] data)
throws org.bouncycastle.crypto.CryptoException
C1 生成随机数的计算出的椭圆曲线点 C2 密文数据 C3 SM3的摘要值
data - 被加密的bytesorg.bouncycastle.crypto.CryptoExceptionpublic byte[] decrypt(byte[] data)
throws org.bouncycastle.crypto.CryptoException
data - SM2密文,实际包含三部分:ECC公钥、真正的密文、公钥和原文的SM3-HASH值org.bouncycastle.crypto.CryptoExceptionpublic byte[] sign(byte[] data)
throws org.bouncycastle.crypto.CryptoException
SmUtils.rsAsn1ToPlain(byte[])方法转换之。data - 加密数据org.bouncycastle.crypto.CryptoExceptionpublic byte[] sign(byte[] data,
byte[] id)
throws org.bouncycastle.crypto.CryptoException
SmUtils.rsAsn1ToPlain(byte[])方法转换之。data - 被签名的数据数据id - 可以为null,若为null,则默认withId为字节数组:"1234567812345678".getBytes()org.bouncycastle.crypto.CryptoExceptionpublic boolean verify(byte[] data,
byte[] sign)
data - 签名后的数据sign - 签名public boolean verify(byte[] data,
byte[] sign,
byte[] id)
data - 数据签名后的数据sign - 签名id - 可以为nullpublic SM2 setMode(org.bouncycastle.crypto.engines.SM2Engine.Mode mode)
public SM2 setDigest(org.bouncycastle.crypto.Digest digest)
public SM2 setEncoding(org.bouncycastle.crypto.signers.DSAEncoding encoding)
public SM2 usePlainEncoding()
public byte[] getD()
public BigInteger getDBigInteger()
public byte[] getQ(boolean isCompressed)
isCompressed - 是否压缩Copyright © 2024 fossc. All rights reserved.