@@ -0,0 +1,2683 @@
+package com.ldcvia;%0A%0Aimport java.security.MessageDigest;%0Aimport javax.crypto.Cipher;%0Aimport javax.crypto.spec.*;%0Aimport javax.crypto.spec.SecretKeySpec;%0A%0Aimport javax.xml.bind.DatatypeConverter;%0A%0A/**%0A* Companion file for our node application.%0A*%0A* NOTE: you will need unrestricted Java security policy files to avoid 'Illegal Key Size' exceptions%0A*%0A* See this link for more:%0A* http://stackoverflow.com/questions/6481627/java-security-illegal-key-size-or-default-parameters%0A*/%0Apublic class NodeCryptoTest %7B%0A%0A  // IV and key: these should be mirrored in the node application%0A  protected static final byte%5B%5D ENC_IV = %220000000000000000%22.getBytes();%0A  protected static final String ENC_KEY = %22hi%22;%0A%0A  private static String decrypt(String encrypted, String seed) throws Exception %7B%0A    byte%5B%5D keyb = seed.getBytes(%22utf-8%22);%0A    MessageDigest md = MessageDigest.getInstance(%22SHA-256%22);%0A    byte%5B%5D thedigest = md.digest(keyb);%0A%0A    SecretKeySpec skey = new SecretKeySpec(thedigest, %22AES%22);%0A    Cipher dcipher = Cipher.getInstance(%22AES/CBC/PKCS5Padding%22);%0A    dcipher.init(Cipher.DECRYPT_MODE, skey, new IvParameterSpec(ENC_IV));%0A    byte%5B%5D clearbyte = dcipher.doFinal(DatatypeConverter.parseHexBinary(encrypted));%0A%0A    return new String(clearbyte);%0A  %7D%0A%0A  /**%0A  * Currently unused%0A  * @param content String to encrypt%0A  * @param key String representing key to use%0A  * @return String representing encrypted content%0A  * @throws Exception%0A  */%0A  public static String encrypt(String content, String key) throws Exception %7B%0A    byte%5B%5D input = content.getBytes(%22utf-8%22);%0A    MessageDigest md = MessageDigest.getInstance(%22SHA-256%22);%0A    byte%5B%5D thedigest = md.digest(key.getBytes(%22utf-8%22));%0A%0A    SecretKeySpec skc = new SecretKeySpec(thedigest, %22AES%22);%0A    Cipher cipher = Cipher.getInstance(%22AES/CBC/PKCS5Padding%22);%0A    cipher.init(Cipher.ENCRYPT_MODE, skc, new IvParameterSpec(ENC_IV));%0A    byte%5B%5D cipherText = new byte%5Bcipher.getOutputSize(input.length)%5D;%0A    int ctLength = cipher.update(input, 0, input.length, cipherText, 0);%0A    ctLength += cipher.doFinal(cipherText, ctLength);%0A%0A    return DatatypeConverter.printHexBinary(cipherText);%0A  %7D%0A%0A  /**%0A  * Test method so we can run this code simply.%0A  * @param args%0A  * @throws Exception%0A  */%0A  public static void main(String%5B%5D args) throws Exception %7B%0A    // This is a sample encrypted JSON object generated from our node app using the same key, algorithm, and IV%0A    String enc = %229584481dcfc5824a6ba6487169d0bdb62c939ce459ec90fff2d685944dfb7fd3db6a2e46991ecc9c88be44bac594cdc3fff2505c846ae3640f58b5f050b02557fcc37a21fdfc833a69490d89750163b61fd8d4087bd211891f97f1d1d5e0e8bb%22;%0A    System.out.println(NodeCryptoTest.decrypt(enc, ENC_KEY));%0A  %7D%0A%0A%7D%0A

Test Java class which works with companion node app