title: AES encrypt in ColdFusion, decrypt in ruby
body: <p>We can't for the life of us figure this out. We need to make ColdFusion encrypt data which ruby will decrypt. We've tried so many different settings on the ColdFusion side, looked through SO posts, looked through Adobe docs, and cannot make it work. ColdFusion needs to encrypt it so ruby can do this:</p>
  
  <pre><code>aes = OpenSSL::Cipher::Cipher.new('aes-256-cbc').encrypt
  aes.key = Digest::MD5.hexdigest("#{password}#{salt}")
  aes.iv = Digest::MD5.hexdigest("#{salt}#{password}")[0,16]
  encrypted = aes.update(data) + aes.final
  </code></pre>
  
  <p>ColdFusion pseudo code</p>
  
  <pre><code>key = tobase64(binaryDecode(lcase(hash(password &amp; salt, "md5")), "hex"))
  iv = lcase(left(hash(salt &amp; password, "md5"), 16))
  encrypt(data, key, "AES/CBC/PKCS5Padding", "Base64", iv)
  </code></pre>
  
  <p>Tried with/without the <code>tobase64</code>/<code>binaryDecode</code> (saw somebody mention that it would handle conversion back internally or something stupid). <code>lcase</code> is to make it generate MD5s that look like what ruby builds.</p>
  
  <p>What are we doing wrong? Endless <code>bad decrypt</code> on the ruby side</p>