程序包 cn.benma666.sm

类 SM2

java.lang.Object
cn.benma666.sm.SM2

public class SM2 extends Object
SM2公钥加密算法实现 包括 -签名,验签 -密钥交换 -公钥加密,私钥解密
作者:
Potato
  • 构造器详细资料

    • SM2

      public SM2()
    • SM2

      public SM2(boolean debug)
  • 方法详细资料

    • isDebug

      public boolean isDebug()
    • setDebug

      public void setDebug(boolean debug)
    • printHexString

      public static void printHexString(byte[] b)
      以16进制打印字节数组
      参数:
      b -
    • encrypt

      public byte[] encrypt(String input, org.bouncycastle.math.ec.ECPoint publicKey)
      公钥加密 * @param input 加密原文
      参数:
      publicKey - 公钥
      返回:
    • encrypt

      public byte[] encrypt(byte[] inputBuffer, org.bouncycastle.math.ec.ECPoint publicKey)
      公钥加密
      参数:
      inputBuffer - 加密原文
      publicKey - 公钥
      返回:
    • encrypt

      public byte[] encrypt(File inputfile, org.bouncycastle.math.ec.ECPoint publicKey) throws Exception
      公钥加密
      参数:
      inputfile - 加密原文
      publicKey - 公钥
      返回:
      抛出:
      Exception
    • decrypt

      public String decrypt(byte[] encryptData, BigInteger privateKey)
      私钥解密
      参数:
      encryptData - 密文数据字节数组
      privateKey - 解密私钥
      返回:
    • generateKeyPair

      public SM2KeyPair generateKeyPair()
      生成密钥对
      返回:
    • exportPublicKey

      public void exportPublicKey(org.bouncycastle.math.ec.ECPoint publicKey, String path)
      导出公钥到本地
      参数:
      publicKey -
      path -
    • importPublicKey

      public org.bouncycastle.math.ec.ECPoint importPublicKey(String path)
      从本地导入公钥
      参数:
      path -
      返回:
    • exportPrivateKey

      public void exportPrivateKey(BigInteger privateKey, String path)
      导出私钥到本地
      参数:
      privateKey -
      path -
    • importPrivateKey

      public BigInteger importPrivateKey(String path)
      从本地导入私钥
      参数:
      path -
      返回:
    • sign

      public SM2.Signature sign(String M, String IDA, SM2KeyPair keyPair)
      签名
      参数:
      M - 签名信息
      IDA - 签名方唯一标识
      keyPair - 签名方密钥对
      返回:
      签名
    • verify

      public boolean verify(String M, SM2.Signature signature, String IDA, org.bouncycastle.math.ec.ECPoint aPublicKey)
      验签
      参数:
      M - 签名信息
      signature - 签名
      IDA - 签名方唯一标识
      aPublicKey - 签名方公钥
      返回:
      true or false
    • main

      public static void main(String[] args) throws UnsupportedEncodingException
      抛出:
      UnsupportedEncodingException