Class SM2AsymmetricAbstract

  • All Implemented Interfaces:
    AsymmetricKeyFormat, AsymmetricSign, CryptoOperation
    Direct Known Subclasses:
    SM2

    public abstract class SM2AsymmetricAbstract
    extends AsymmetricAbstract
    implements CryptoOperation, AsymmetricKeyFormat
    SM2国密算法抽象类
    默认算法为C1C3C2,默认曲线sm2p256v1
    需要依赖BouncyCastleProvider库
    C1:表示椭圆曲线上的一个点,用于进行签名或者加密过程中的一些运算
    C2:表示加密的结果,即加密后的数据
    C3:表示对数据的签名值,用于验证数据的完整性,不是加密过程中的一部分
    线程安全类
    Author:
    Pan
    • Field Detail

      • EC_PARAMETERS

        public static final org.bouncycastle.asn1.x9.X9ECParameters EC_PARAMETERS
        国密曲线参数
      • EC_DOMAIN_PARAMETERS

        public static final org.bouncycastle.crypto.params.ECDomainParameters EC_DOMAIN_PARAMETERS
        国密椭圆曲线域参数,包含曲线参数、基点、阶及余因子
    • Method Detail

      • getPublicKey

        public org.bouncycastle.crypto.params.ECPublicKeyParameters getPublicKey()
        获取公钥
        Returns:
        ECPublicKeyParameters
      • getPrivateKey

        public org.bouncycastle.crypto.params.ECPrivateKeyParameters getPrivateKey()
        获取私钥
        Returns:
        ECPrivateKeyParameters
      • getEcPoint

        public org.bouncycastle.math.ec.ECPoint getEcPoint()
        获取公钥Q值
        Returns:
        ECPoint
      • getQ

        public byte[] getQ()
        获取公钥Q值
        Returns:
        byte[]
      • getQ

        public byte[] getQ​(boolean isCompress)
        获取公钥Q值
        Parameters:
        isCompress - 是否压缩
        Returns:
        byte[]
      • getD

        public BigInteger getD()
        获取私钥D值
        Returns:
        BigInteger
      • getDBytes

        public byte[] getDBytes()
        获取私钥D值
        Returns:
        dBytes
      • getUserId

        public abstract byte[] getUserId()
        获取用户id
        Returns:
        byte[]
      • getWithRandom

        public abstract boolean getWithRandom()
        判断签名时是否使用随机数
        Returns:
        boolean
      • doFinal

        public byte[] doFinal​(CipherMode cipherMode,
                              byte[] content)
        最终执行加解密方法
        Specified by:
        doFinal in class AsymmetricAbstract
        Parameters:
        cipherMode - 加解密模式
        content - 加解密内容
        Returns:
        byte[] 密文
      • sign

        public byte[] sign​(byte[] data)
        Description copied from class: AsymmetricAbstract
        对数据进行签名
        Specified by:
        sign in class AsymmetricAbstract
        Parameters:
        data - 待签名的原始数据(字节数组)
        Returns:
        byte[] 签名值(字节数组)
      • verify

        public boolean verify​(byte[] data,
                              byte[] signature)
        Description copied from class: AsymmetricAbstract
        验证签名
        Specified by:
        verify in class AsymmetricAbstract
        Parameters:
        data - 原始数据
        signature - 签名值
        Returns:
        boolean true表示验证通过
      • createKeyObject

        public AsymmetricKey createKeyObject()
        创建Key密钥对对象(可用于缓存)
        默认Base64编码格式
        Returns:
        AsymmetricKey
      • createKeyObject

        public AsymmetricKey createKeyObject​(boolean isBase64)
        创建Key密钥对对象(可用于缓存)
        自定义编码格式(true:Base64, false:十六进制)
        Parameters:
        isBase64 - true:Base64, false:十六进制
        Returns:
        AsymmetricKey