szvone
2020-01-09 00:00:54 +08:00
有这么一个函数:
public static String a(String str, String str2) throws Exception {
Cipher v1 = Cipher.getInstance("RSA");
v1.init(1, KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decode(str2,Base64.DEFAULT))));
return Base64.encodeToString(v1.doFinal(str.getBytes()),Base64.DEFAULT);
}
用下面的代码调用:
String key = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAI6Nnwc6Doyk6sFvN/oVbsjS+EhV661qfVrgfJ/PTNev\n" +
"uDjQQvI8pjooKreTab2sbSUuv2otPxfLC+IyN58ye7UCAwEAAQ==";
String res = null;
try {
res = a("13888888888",key);
} catch (Exception e) {
e.printStackTrace();
}
得到的 res 始终会是:LTaf1+LNtbI0NHMISTHuiY10rYKQK0BhqkgHqcrM1N8nYWZXUR0WuKMvU4ZzCZD1D0hdO9ZhcXuM1NdL0mOSyg==
且这个 res 永远都是这个值,RSA 加密的话不是每次都会变动吗,为啥这个就不会变动呢?
这个用 javascript 怎么实现呢?