/**
- @author LiWenBin
- RSA非堆成加密方法
*/
public class RSAController {
@Value("${pcPrivateKey:}")
private String pcPrivateKey;
@Value("${pcPublicKey:}")
private String pcPublicKey;
/**
* 公钥加密私钥解密
*/
@GetMapping("/encryption")
public String bind() {
RSA rsa = new RSA(null, pcPublicKey);
String data="123456";//密码
String s = rsa.encryptBase64(data, KeyType.PublicKey);
System.out.println(s);//公钥加密后密码
RSA rsa2 = new RSA(pcPrivateKey, null);
String s1 = rsa2.decryptStr(s, KeyType.PrivateKey);
System.out.println(s1);//私钥解密后密码
return s1;
}
/**
* 私钥加密公钥解密
*/
@GetMapping("/encryption2")
public String bindas() {
RSA rsa = new RSA(pcPrivateKey,null );
String data="123456";//密码
String s = rsa.encryptBase64(data, KeyType.PrivateKey);
System.out.println(s);//私钥加密后密码
RSA rsa2 = new RSA(null, pcPublicKey);
String s1 = rsa2.decryptStr(s, KeyType.PublicKey);
System.out.println(s1);//公钥解密后密码
return s1;
}
}