js:
// Struts2 Action方法中:
// 将公钥的 modulus 和 exponent 传给页面。
// Hex -> apache commons-codec
RSAPublicKey publicKey = RSAUtils.getDefaultPublicKey();
ActionContext.getContext().put(
"modulus"
,
new
String(Hex.encodeHex(publicKey.getModulus().toByteArray())));
ActionContext.getContext().put(
"exponent"
,
new
String(Hex.encodeHex(publicKey.getPublicExponent().toByteArray())));
// 页面里,Javascript对明文进行加密:
var modulus = $(
'#hid_modulus'
).val(), exponent = $(
'#hid_exponent'
).val();
var key = RSAUtils.getKeyPair(exponent,
''
, modulus);
pwd1 = RSAUtils.encryptedString(key, pwd1);
pwd2 = RSAUtils.encryptedString(key, pwd2);
百度网盘 security.js 下载 http://pan.baidu.com/s/1ge4oHMj
百度网盘 java RSAUtils 下载 http://pan.baidu.com/s/1dEWJcZ3
转载于:https://blog.51cto.com/wox666/1924167