title: Crypto in Nodejs and Ruby
body: <p>I want crypto a string and pass to Rails app,so I find the crypto  library both in Nodejs and Ruby.</p>
  
  <p>In Nodejs:</p>
  
  <pre><code>var crypto = require('crypto'),
      algorithm = 'aes-256-ctr',
      password = 'd6F3Efeqd6F3Efeqd6F3Efeqd6F3Efeq';
  
  function encrypt(text){
    var cipher = crypto.createCipher(algorithm,password)
    var crypted = cipher.update(text,'ascii',"base64")
    crypted += cipher.final("base64");
    return crypted;
  }
  </code></pre>
  
  <p>The result is :</p>
  
  <pre><code>encrypt("1") //-输出 2g==
  </code></pre>
  
  <p>In Ruby</p>
  
  <pre><code>def encrypt(des_text)
      des = OpenSSL::Cipher::Cipher.new('aes-256-ctr')
      des.encrypt
      des.key = 'd6F3Efeqd6F3Efeqd6F3Efeqd6F3Efeq'
      result = des.update(des_text)
      result &lt;&lt; des.final
      return Base64.encode64 result
  end
  </code></pre>
  
  <p>The result is :</p>
  
  <pre><code>encrypt("1")  # 输出 1A==
  </code></pre>
  
  <p>So I use the same way and key to crypto  a same string,Why the result is not the same? </p>