对接雪亮平台
This commit is contained in:
parent
aa9a4285d4
commit
ba1ea1439a
|
|
@ -0,0 +1,62 @@
|
|||
package com.dkl.large.utli;
|
||||
|
||||
import com.koal.kms.sdk.ed.KmsSdkException;
|
||||
import com.koal.kms.sdk.ed.KmsUtil;
|
||||
import com.koal.kms.sdk.ed.Mode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
import static org.springframework.util.SerializationUtils.serialize;
|
||||
|
||||
public class EnciphermentUtil {
|
||||
public static final Logger log = LoggerFactory.getLogger(EnciphermentUtil.class);
|
||||
|
||||
public static void main(String[] args) throws KmsSdkException {
|
||||
|
||||
String a = kmsEncrypt("机密19985858585");
|
||||
|
||||
}
|
||||
/**
|
||||
* 数据加密
|
||||
* originData 待加密数据
|
||||
*/
|
||||
public static String kmsEncrypt( String originData) throws KmsSdkException {
|
||||
log.info("原始数据={}",originData);
|
||||
byte[] encryptData = KmsUtil.encrypt(originData.getBytes(), Mode.CBC);
|
||||
// 若要保存密文,使用Base64做编码处理
|
||||
String saveEncryptData = Base64.getEncoder().encodeToString(encryptData);
|
||||
log.info("加密数据={}",saveEncryptData);
|
||||
return saveEncryptData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据解密
|
||||
* encryptData 加密后的数据
|
||||
*/
|
||||
|
||||
public static String kmsDencrypt(String encryptData) throws KmsSdkException {
|
||||
log.info("加密数据={}",encryptData);
|
||||
// 解密前使用Base64做解码处理
|
||||
byte[] decryptData = Base64.getDecoder().decode(encryptData);
|
||||
byte[] decryptResult = KmsUtil.decrypt(decryptData, Mode.CBC);
|
||||
String result=new String(decryptResult);
|
||||
log.info("解密后={}",result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 一致性签名文档
|
||||
* signatureData 需要获取验证的数据
|
||||
*/
|
||||
|
||||
public static String kmsSign(byte[] signatureData) throws KmsSdkException {
|
||||
byte[] decryptResult = KmsUtil.hmacSM3Encrypt(signatureData);
|
||||
String saveEncryptData = Base64.getEncoder().encodeToString(decryptResult);
|
||||
log.info("签名码={}",saveEncryptData);
|
||||
return saveEncryptData;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue