我在下面有一个非常简单的示例来尝试说明我想要做什么。我的 Java 类“CommonUtils”有一个加密和解密字符串的方法。我想在将 logonuidfield 和 logonpassfield 写入 cookie 之前对其进行加密。我知道直接从 Javascript 调用 CommonUtils.xorEncode(~) 是不可能的,但是是否可以解决这些字段的值在写入 cookie 之前通过 CommonUtils.xorEncode(~) 传递的方法?
我不想用javascript编写加密方法。我希望它由 Java 类完成。我的猜测是,如果不使用 LiveConnect 或类似的东西,我想要做的事情是不可能的。
提前致谢。
<%@ page import="package.CommonUtils" %>
<HTML>
<SCRIPT LANGUAGE=JavaScript>
function setCookies() {
var email = document.getElementById("logonuidfield").value;
var password = document.getElementById("logonpassfield").value;
writeCookie("EmailText",email);
writeCookie("PasswordText",password);
}
function writeCookie(name, value) {
document.cookie = name + "=" + escape(value);
}
</script>
<body>
<tr>
<td>
<%
String message = "This is a test message.";
out.println("<Label>This is the original message: " + message + "</Label><br>");
out.println("<Label>Hex before encrypting : " + CommonUtils.printStringHex(message) + "</Label><br>");
message = CommonUtils.xorEncode(message);
out.println("<Label>Hex after encrypting : " + CommonUtils.printStringHex(message) + "</Label><br>");
message = CommonUtils.xorDecode(message);
out.println("<Label>Hex after decrypting : " + CommonUtils.printStringHex(message) + "</Label><br>");
out.println("<Label>This is the final message : " + message + "</Label><br>");
%>
</td>
</tr>
<FORM name="logonForm" id="logonForm" autocomplete="off" onsubmit="setCookies()" method="post" action="" >
<li>
<input type="text" id="logonuidfield" placeholder="email address*" style="width: 100%" name="j_user" type="email" value="" title="Email address *"/>
</li>
<li>
<input type="password" id="logonpassfield" placeholder="Password*" style="width: 100%" name="j_password" />
</li>
<li>
<input type="submit" value="Log in" name="uidPasswordLogon"/>
</li>
</form>