Package cn.gmkit.sm2

Class SM2Ciphertexts

java.lang.Object
cn.gmkit.sm2.SM2Ciphertexts

public final class SM2Ciphertexts extends Object
SM2 密文编码转换工具。

负责在原始 C1/C2/C3 布局、GmSSL 兼容布局以及 ASN.1 DER 编码之间做转换。

  • Method Details

    • parse

      public static SM2Ciphertext parse(byte[] ciphertext, SM2CipherMode mode)
      解析SM2密文数据
      Parameters:
      ciphertext - 密文字节数组
      mode - 密文排列模式
      Returns:
      SM2密文对象
      Throws:
      GmkitException - 如果密文格式无效
    • encodeDer

      public static byte[] encodeDer(byte[] ciphertext, SM2CipherMode mode)
      将密文编码为DER格式
      Parameters:
      ciphertext - 原始密文字节数组
      mode - 密文排列模式
      Returns:
      DER编码的密文
      Throws:
      GmkitException - 如果编码失败
    • encodeAsn1

      public static byte[] encodeAsn1(byte[] ciphertext, SM2CipherMode mode)
      将原始密文编码为 ASN.1 DER 格式。
      Parameters:
      ciphertext - 原始密文字节数组
      mode - 密文排列模式
      Returns:
      ASN.1 DER 编码密文
    • decodeDer

      public static byte[] decodeDer(byte[] derCiphertext, SM2CipherMode mode)
      将DER格式的密文解码为原始格式
      Parameters:
      derCiphertext - DER编码的密文
      mode - 密文排列模式
      Returns:
      原始格式的密文字节数组
      Throws:
      GmkitException - 如果解码失败
    • decodeAsn1

      public static byte[] decodeAsn1(byte[] asn1Ciphertext, SM2CipherMode mode)
      将 ASN.1 DER 密文解码为原始 SM2 密文。
      Parameters:
      asn1Ciphertext - ASN.1 DER 编码密文
      mode - 密文排列模式
      Returns:
      原始 SM2 密文
    • decodeAuto

      public static byte[] decodeAuto(byte[] ciphertext, SM2CipherMode mode)
      自动识别原始密文和 ASN.1 DER 密文。
      Parameters:
      ciphertext - 密文字节数组
      mode - 密文排列模式
      Returns:
      原始 SM2 密文