修改机密性和完整性校验

This commit is contained in:
sh
2026-04-07 18:26:41 +08:00
parent 5cfa574f0b
commit a1b880f817
5 changed files with 62 additions and 31 deletions

View File

@@ -81,9 +81,11 @@ public class EncryptDecryptUtil {
*/
public String sm4Encrypt(String cipherIdentification, String originData)
throws CryptoClient.CryptoException {
log.info("开启机密性保护");
byte[] cipher = CryptoHelper.symmEncrypt(cipherIdentification, SymAlg.QK_SGD_SM4_CBC,
SymAlgPaddingMode.QK_SYMALG_PADDING_PKCS7, IV.getBytes(StandardCharsets.UTF_8),
originData.getBytes(StandardCharsets.UTF_8));
log.info("生成相应密文");
return Base64.getEncoder().encodeToString(cipher);
}
@@ -130,8 +132,10 @@ public class EncryptDecryptUtil {
*/
public String sm3Hash(String cipherIdentification, String originData)
throws CryptoClient.CryptoException {
log.info("开始完整性保护");
byte[] hash = CryptoHelper.calculateMAC(cipherIdentification, MacAlg.QK_HMAC_SM3,
originData.getBytes(StandardCharsets.UTF_8));
log.info("已生成响应哈希值");
return Base64.getEncoder().encodeToString(hash);
}
@@ -156,8 +160,11 @@ public class EncryptDecryptUtil {
*/
public boolean sm3Verify(String cipherIdentification, String originData, String hashData)
throws CryptoClient.CryptoException {
return CryptoHelper.verifyMAC(cipherIdentification, MacAlg.QK_HMAC_SM3,
log.info("开始完整性校验");
boolean b=CryptoHelper.verifyMAC(cipherIdentification, MacAlg.QK_HMAC_SM3,
originData.getBytes(StandardCharsets.UTF_8), Base64.getDecoder().decode(hashData));
log.info("完整性校验结束");
return b;
}
}