Class UserCertDecryptor
java.lang.Object
org.ofdrw.crypto.decryptor.UserCertDecryptor
- All Implemented Interfaces:
UserFEKDecryptor
OFD 用户证书解密器
使用 SM2 私钥解密 C1C3C2 格式的密文,恢复文件加密密钥(FEK)。
对应加密器:UserCertEncryptor
加密时使用公钥加密 FEK,解密时使用对应的私钥解密。
- Since:
- 2.4.0
- Author:
- 权观宇
-
Constructor Summary
ConstructorsConstructorDescriptionUserCertDecryptor(String username, org.bouncycastle.crypto.params.ECPrivateKeyParameters privateKey) 创建证书解密器UserCertDecryptor(org.bouncycastle.crypto.params.ECPrivateKeyParameters privateKey) 创建证书解密器(不指定用户名,匹配第一个 UserInfo) -
Method Summary
Modifier and TypeMethodDescriptiondecrypt(org.ofdrw.core.crypto.encryt.UserInfo userInfo) 从 UserInfo 中解密出 FEK 和 IV加密保护方案标识目标用户名
-
Constructor Details
-
UserCertDecryptor
public UserCertDecryptor(String username, org.bouncycastle.crypto.params.ECPrivateKeyParameters privateKey) 创建证书解密器- Parameters:
username- 目标用户名,null 时匹配第一个 UserInfoprivateKey- 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:
decryptin interfaceUserFEKDecryptor- Parameters:
userInfo- 加密的用户信息- Returns:
- 解密结果,包含 FEK(16字节) 和 IV(16字节)
- Throws:
org.bouncycastle.crypto.CryptoException- 解密失败(密钥不匹配或数据损坏)
-
encryptCaseId
Description copied from interface:UserFEKDecryptor加密保护方案标识必须与加密时使用的方案标识一致,参见
ProtectionCaseID:- "1.1.1" — 口令加密(EncryptGMPassword)
- "1.1.2" — 证书加密(EncryptGMCert)
解密时用于与密钥描述文件(DecyptSeed)中的 EncryptCaseId 进行匹配。
- Specified by:
encryptCaseIdin interfaceUserFEKDecryptor- Returns:
- 加密保护方案标识
-
getUsername
Description copied from interface:UserFEKDecryptor目标用户名用于与 UserInfo 中的 UserName 进行匹配,定位该用户对应的加密信息。 返回 null 时表示匹配第一个 UserInfo(不按用户名过滤)。
- Specified by:
getUsernamein interfaceUserFEKDecryptor- Returns:
- 目标用户名,可为 null
-