Package cn.gmkit.sm9

Class SM9SignKey

java.lang.Object
cn.gmkit.sm9.SM9SignKey
All Implemented Interfaces:
AutoCloseable

public final class SM9SignKey extends Object implements AutoCloseable
SM9 用户签名私钥。

SM9SignMasterKey.extractKey(String) 派生,或从加密 PEM 文件导入。 持有一个指向 native 资源的句柄,使用完毕后应调用 close() 释放(推荐使用 try-with-resources)。

  • Method Details

    • getId

      public String getId()
      返回该签名私钥对应的用户标识(ID)。
      Returns:
      用户标识,可能为 null(从 PEM 导入且未提供时)
    • exportEncryptedPrivateKeyInfoPem

      public void exportEncryptedPrivateKeyInfoPem(String password, String file)
      将该签名私钥以口令加密为 PEM 文件。
      Parameters:
      password - 加密口令
      file - 输出文件路径
      Throws:
      SM9Exception - 口令/路径为空、对象已关闭或 native 写入失败时抛出
    • importEncryptedPrivateKeyInfoPem

      public static SM9SignKey importEncryptedPrivateKeyInfoPem(String password, String file, String id)
      从加密 PEM 文件导入用户签名私钥。
      Parameters:
      password - 解密口令
      file - PEM 文件路径
      id - 该私钥对应的用户标识,可为 null
      Returns:
      导入的签名私钥
      Throws:
      SM9Exception - native 不可用、参数无效、口令错误或 PEM 读取失败时抛出
    • close

      public void close()
      释放底层 native 资源。重复调用安全。
      Specified by:
      close in interface AutoCloseable