Class UserPasswordDecryptor
java.lang.Object
org.ofdrw.crypto.decryptor.UserPasswordDecryptor
- All Implemented Interfaces:
UserFEKDecryptor
OFD 用户口令解密器
使用口令通过密钥派生函数(KDF)生成密钥加密密钥(KEK), 然后用 SM4-CBC 解密文件加密密钥(FEK)的包装密钥。
KDF 遵循 GB/T 32918.3-2016 5.4.3 密钥派生函数。
对应加密器:UserPasswordEncryptor
- Since:
- 2.4.0
- Author:
- 权观宇
-
Constructor Summary
ConstructorsConstructorDescriptionUserPasswordDecryptor(String password) 创建口令解密器(不指定用户名,匹配第一个 UserInfo)UserPasswordDecryptor(String username, String password) 创建口令解密器 -
Method Summary
Modifier and TypeMethodDescriptiondecrypt(org.ofdrw.core.crypto.encryt.UserInfo userInfo) 从 UserInfo 中解密出 FEK 和 IV加密保护方案标识目标用户名
-
Constructor Details
-
UserPasswordDecryptor
创建口令解密器- Parameters:
username- 目标用户名,null 时匹配第一个 UserInfopassword- 加密时使用的口令(与加密时一致)- Throws:
IllegalArgumentException- 口令为空
-
UserPasswordDecryptor
创建口令解密器(不指定用户名,匹配第一个 UserInfo)- Parameters:
password- 加密时使用的口令
-
-
Method Details
-
decrypt
public DecryptResult decrypt(org.ofdrw.core.crypto.encryt.UserInfo userInfo) throws org.bouncycastle.crypto.CryptoException 从 UserInfo 中解密出 FEK 和 IV使用 KDF 派生的 KEK + UserInfo 中的 IV,SM4-CBC 解密 EncryptedWK → 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
-