给BC_KeyManager增加公钥加密的静态函数

This commit is contained in:
free will
2021-07-21 09:58:06 +08:00
parent e56bb70fb6
commit 595d0f5212
@@ -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