38 lines
805 B
Java
38 lines
805 B
Java
package com.zhgd.xmgl.util;
|
|
|
|
public class RsaTool {
|
|
|
|
/**
|
|
* RSA公钥加密
|
|
*
|
|
* @param str
|
|
* 加密字符串
|
|
* @param publicKey
|
|
* 公钥
|
|
* @return 密文
|
|
* @throws Exception
|
|
* 加密过程中的异常信息
|
|
*/
|
|
public static byte[] encrypt( byte[] str, String publicKey ) throws Exception{
|
|
//base64编码的公钥
|
|
return RSAUtils.encryptByPublicKey(str, publicKey);
|
|
}
|
|
|
|
/**
|
|
* RSA私钥解密
|
|
*
|
|
* @param str
|
|
* 加密字符串
|
|
* @param privateKey
|
|
* 私钥
|
|
* @return 铭文
|
|
* @throws Exception
|
|
* 解密过程中的异常信息
|
|
*/
|
|
public static byte[] decrypt(byte[] str, String privateKey) throws Exception{
|
|
return RSAUtils.decryptByPrivateKey(str, privateKey);
|
|
}
|
|
|
|
}
|
|
|