title: HTML Form Encryption via Java Class
body: <p>I have a very simple example below to try and illustrate what I want to do.  My Java class "CommonUtils" has a method to encrypt and decrypt a string.  I want to encrypt  logonuidfield and logonpassfield before I write them to a cookie.  I understand calling CommonUtils.xorEncode(~) directly from Javascript is not possible, but is it possible to have a work around whereby the value of these fields are passed through CommonUtils.xorEncode(~) prior to the cookie being written?</p>
  
  <p>I do not want to have the encryption method written in javascript.  I would prefer it to be in the done by the Java class.  My guess it that without using LiveConnect or some such, what I am trying to do is not possible.</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>&lt;%@ page import="package.CommonUtils" %&gt;
  
  &lt;HTML&gt;
  &lt;SCRIPT LANGUAGE=JavaScript&gt;
  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);
  }
  &lt;/script&gt;
  
  &lt;body&gt;
  &lt;tr&gt;
      &lt;td&gt;
          &lt;%  
              String message = "This is a test message.";
  
              out.println("&lt;Label&gt;This is the original message: " + message + "&lt;/Label&gt;&lt;br&gt;");
              out.println("&lt;Label&gt;Hex before encrypting       : " + CommonUtils.printStringHex(message)  + "&lt;/Label&gt;&lt;br&gt;");
              message = CommonUtils.xorEncode(message);
              out.println("&lt;Label&gt;Hex after encrypting        : " + CommonUtils.printStringHex(message) + "&lt;/Label&gt;&lt;br&gt;");
              message = CommonUtils.xorDecode(message);
              out.println("&lt;Label&gt;Hex after decrypting        : " + CommonUtils.printStringHex(message) + "&lt;/Label&gt;&lt;br&gt;");
              out.println("&lt;Label&gt;This is the final message   : " + message + "&lt;/Label&gt;&lt;br&gt;");
          %&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;FORM name="logonForm" id="logonForm" autocomplete="off" onsubmit="setCookies()" method="post" action="" &gt;
      &lt;li&gt;                                    
          &lt;input type="text" id="logonuidfield" placeholder="email address*" style="width: 100%" name="j_user" type="email" value="" title="Email address *"/&gt;
      &lt;/li&gt;
      &lt;li&gt;
          &lt;input type="password" id="logonpassfield" placeholder="Password*" style="width: 100%" name="j_password" /&gt;
      &lt;/li&gt;
      &lt;li&gt;
          &lt;input type="submit" value="Log in" name="uidPasswordLogon"/&gt;
      &lt;/li&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>
  </p>