Class UserCertDecryptor

java.lang.Object
org.ofdrw.crypto.decryptor.UserCertDecryptor
All Implemented Interfaces:
UserFEKDecryptor

public class UserCertDecryptor extends Object implements UserFEKDecryptor
OFD 用户证书解密器

使用 SM2 私钥解密 C1C3C2 格式的密文,恢复文件加密密钥(FEK)。 对应加密器:UserCertEncryptor

加密时使用公钥加密 FEK,解密时使用对应的私钥解密。

Since:
2.4.0
Author:
权观宇
  • Constructor Details

    • UserCertDecryptor

      public UserCertDecryptor(String username, org.bouncycastle.crypto.params.ECPrivateKeyParameters privateKey)
      创建证书解密器
      Parameters:
      username - 目标用户名,null 时匹配第一个 UserInfo
      privateKey - SM2 私钥(用于解密 FEK)
      Throws:
      IllegalArgumentException - 私钥为空
    • UserCertDecryptor

      public UserCertDecryptor(org.bouncycastle.crypto.params.ECPrivateKeyParameters privateKey)
      创建证书解密器(不指定用户名,匹配第一个 UserInfo)
      Parameters:
      privateKey - SM2 私钥
  • Method Details

    • decrypt

      public DecryptResult decrypt(org.ofdrw.core.crypto.encryt.UserInfo userInfo) throws org.bouncycastle.crypto.CryptoException
      从 UserInfo 中解密出 FEK 和 IV

      使用 SM2 私钥解密 ASN.1 编码的 EncryptedWK(C1C3C2格式) → FEK。

      Specified by:
      decrypt in interface UserFEKDecryptor
      Parameters:
      userInfo - 加密的用户信息
      Returns:
      解密结果,包含 FEK(16字节) 和 IV(16字节)
      Throws:
      org.bouncycastle.crypto.CryptoException - 解密失败(密钥不匹配或数据损坏)
    • encryptCaseId

      public String encryptCaseId()
      Description copied from interface: UserFEKDecryptor
      加密保护方案标识

      必须与加密时使用的方案标识一致,参见 ProtectionCaseID

      • "1.1.1" — 口令加密(EncryptGMPassword)
      • "1.1.2" — 证书加密(EncryptGMCert)

      解密时用于与密钥描述文件(DecyptSeed)中的 EncryptCaseId 进行匹配。

      Specified by:
      encryptCaseId in interface UserFEKDecryptor
      Returns:
      加密保护方案标识
    • getUsername

      public String getUsername()
      Description copied from interface: UserFEKDecryptor
      目标用户名

      用于与 UserInfo 中的 UserName 进行匹配,定位该用户对应的加密信息。 返回 null 时表示匹配第一个 UserInfo(不按用户名过滤)。

      Specified by:
      getUsername in interface UserFEKDecryptor
      Returns:
      目标用户名,可为 null