mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-18 08:20:25 +08:00
给BC_KeyManager增加公钥加密的静态函数
This commit is contained in:
@@ -98,7 +98,8 @@ public class BC_KeyManager {
|
||||
// }
|
||||
|
||||
/**
|
||||
* 私钥签名
|
||||
* SM2私钥签名
|
||||
* 注意这里有base64加密
|
||||
* @param text
|
||||
* @return
|
||||
* @throws CryptoException
|
||||
@@ -120,7 +121,8 @@ public class BC_KeyManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 公钥验签
|
||||
* SM2公钥验签
|
||||
* 注意这里有base64解密
|
||||
* @param text
|
||||
* @param signature
|
||||
* @param pubkey
|
||||
@@ -138,6 +140,24 @@ public class BC_KeyManager {
|
||||
return publicKey.verify(text,sig);
|
||||
}
|
||||
|
||||
/**
|
||||
* SM2公钥加密
|
||||
* @param pubkey
|
||||
* @param text
|
||||
* @return
|
||||
* @throws InvalidCipherTextException
|
||||
*/
|
||||
public static byte[] sm2encrypt(byte[] pubkey,byte[] text) throws InvalidCipherTextException {
|
||||
// 生成公钥
|
||||
SM2PublicKey publicKey=new SM2PublicKey();
|
||||
boolean flag=publicKey.setBytes(pubkey);
|
||||
if(!flag){
|
||||
return null;
|
||||
}
|
||||
// 使用公钥加密原文
|
||||
return publicKey.encrypt(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* SM4对称加密
|
||||
* @param secretkey
|
||||
|
||||
Reference in New Issue
Block a user