ABN 25 173 915 011 markomedia - web development

markomedia - web development

  • Home
  • Contact
  • Blog

October 15, 2011

AES-128 padded encryption/decryption with Railo, Java and AS3

  • markomedia
    • AS3
      • AES-128 padded encryption/decryption with Railo, Java and AS3
Share |
  • Author
    Marko Tomic
    Category
    AS3, Java, Railo
    Tags
    AS3, java, Railo
    Comments
    0

    I’ve recently been working on text file decryption using Railo server. My files were encrypted in ActionScript 3 with the powerful AES-128 algorithm. For more info on AS3 encryption see Hurlant Crypto demo.

    My challenge was to decypt this heavily encrypted content on a different platform, i.e. Railo with underlying Java Cipher capabilities.

    The 6 things I knew about the encrypted content were:
    1. Encryption Method – AES
    2. Mode – CBC (Cipher-block chaining)
    3. Padding – PKCS5
    4. Initialisation Vector (IV) – given hex string
    5. Passphrase – given hex string
    6. Encrypted text file saved in base64 encoded string.

    For my records, this is how I went about decrypting on Railo:

    <cfscript>
    // Create some java objects
    IvParameterSpec = createObject("java", "javax.crypto.spec.IvParameterSpec");
    Cipher = createObject("java", "javax.crypto.Cipher");
    SecretKeySpec = createObject("java", "javax.crypto.spec.SecretKeySpec");
    BASE64Decoder = createObject("java", "sun.misc.BASE64Decoder");
    Str = createObject("java", "java.lang.String");
    MessageDigest = createObject("java", "java.security.MessageDigest");
     
    encryptedFileContent = "base64encodedcontent";
    password = binarydecode("somehexpassphrase", "hex");
    iv = binarydecode("somehexivstring", "hex");
     
    skeySpec = SecretKeySpec.init(password, "AES");
    ivSpec = IvParameterSpec.init(iv);
    cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
     
    encryptedContent = BASE64Decoder.decodeBuffer(encryptedFileContent);
    cipher.init(Cipher.DECRYPT_MODE,skeySpec,ivSpec);
    decryptedBytes = cipher.doFinal(encryptedContent);
    decryptedString = Str.init(decryptedBytes);
    </cfscript>

    Now that we know how the decryption works, encrypting data on Railo should be a piece of cake. For example:

    <cfscript>
    password = "somepassphrase";
    stringToEncrypt = "stringToEncrypt";
    md = MessageDigest.getInstance("MD5");
    md.update(password.getBytes("UTF-8"), 0, password.length());
    rawKey = md.digest();
     
    skeySpec = SecretKeySpec.init(rawKey, "AES");
    ivSpec = IvParameterSpec.init(rawKey);
    cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivSpec);
     
    encryptedbytes = cipher.doFinal(stringToEncrypt.getBytes());
    </cfscript>

    The only thing you need to be aware of is the format of parameters passed into encryption/decryption logic, and convert them appropriately. These parameters can be either plain, base64 or hex strings.

    Who would’ve thought that reverse engineering could be som much fun :)

    Cheers
    Marko

  • Previous post
  • Next post
Top

Related posts

  • IE6, IE7, IE8, & IE9 on OS X in Virtual Machine
  • opendiff and FileMerge on OS X
  • Bandwidth throttling on OS X
  • bash script useful tips
  • apr_sockaddr_info_get() failed for mydomain.com

Share this post

Author Marko Tomic

Gravatar

Leave a comment

No comments yet.

Search

QR Code

Recent Posts

  • IE 8 and IE6 on OS X VirtualBox

    IE6, IE7, IE8, & IE9 on OS X in Virtual Machine

  • FileMerge

    opendiff and FileMerge on OS X

  • Bandwidth throttling on OS X

Popular

  • Verizon Activates 2.2 Million iPhones in First Quarter

  • Amazon Server Trouble, Obama’s Facebook Visit.

  • Best Practices for Android Developers

Comments

  • Marko Tomic on Zen Cart to VirtueMart csv export
  • snake on Zen Cart to VirtueMart csv export
  • Marko Tomic on Flash to Flex ComponentEvent coercion error solved
  • Thomas on Flash to Flex ComponentEvent coercion error solved
  • Increase PHP file upload limit – markomedia – Web Development | Files U, Apache on Increase PHP file upload limit

Tags

  • Apache6
  • AS36
  • bash2
  • ColdFusion2
  • command1
  • difftool1
  • DVD1
  • filemerge1
  • Flash3
  • Flex6
  • general2
  • Handbreak1
  • HOWTO8
  • IE61
  • IE71
  • IE81
  • IE91
  • iPhone1
  • iTunes1
  • Jaber1
  • java5
  • Linux3
  • MySQL3
  • networking1
  • opendiff1
  • OS X8
  • PHP3
  • Railo4
  • Red52
  • S31
  • shell3
  • SQL1
  • SSH2
  • SSL1
  • SVN1
  • tar1
  • Terminal3
  • Tigase1
  • Tomcat2
  • Ubuntu2
  • utilities1
  • VirtueMart1
  • XMPP1
  • ZenCart2
  • zip1

Contact us

  • Call us

Archive

  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • May 2011
  • December 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009

Navigation

  • Home
  • Contact
  • Blog

Archives

  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • May 2011
  • December 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009

From the blog

  • IE6, IE7, IE8, & IE9 on OS X in Virtual Machine

  • opendiff and FileMerge on OS X

  • Bandwidth throttling on OS X

  • bash script useful tips

  • apr_sockaddr_info_get() failed for mydomain.com

About us

Marko Tomic - Web professional and an Adobe Certified Expert with over 10 years of commercial experience using variety of technologies.

Connect

Facebook icon Twitter icon Email icon RSS icon