RSA+Base64加解密Java工具类RSAUtil(公钥和私钥请自行生成)
import java.io.IOException;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Properties;
import javax.crypto.Cipher;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class RSAUtil {
/**
* RSA+BASE64加密(先RSA加密,然后Base64加密)
* @param secretContent:secretContent要加密的内容
* @return
*/
public static String encrypt(String secretContent) {
String byte2Base64 = "";
try {
//===============生成公钥和私钥,公钥传给客户端,私钥服务端保留==================
//生成RSA公钥和私钥,并Base64编码
String filePath = "key.properties";
Properties prop = new Properties();
String PRIVATEKEY = null;
String PUBLICKEY = null;
prop.load(RSAUtil.class.getClassLoader().getResourceAsStream(filePath));
PRIVATEKEY = prop.getProperty("PRIVATEKEY");
PUBLICKEY = prop.getProperty("PUBLICKEY");
//=================客户端=======&#