title: Node.js Crypto work only for string with length less than 15
body: <p>I have two function to encrypt and decrypt strings in node.js and both work fine, til input string have length less than 15 characters and above this they will not work. Below are both function i used in nodejs with crypto module.</p>
  
  <pre><code>encrypt: function (input, password) {
      try{
          input = input.toString();
          var m = crypto.createHash('md5');
          m.update(password);
          var key = m.digest('hex');
  
          m = crypto.createHash('md5');
          m.update(password + key);
          var iv = m.digest('hex');
  
          var data = new Buffer(input, 'utf8').toString('binary');
  
          var cipher = crypto.createCipheriv('aes-256-cbc', key, iv.slice(0,16));
          var encrypted = cipher.update(data, 'binary') + cipher.final('binary');
          var encoded = new Buffer(encrypted, 'binary').toString('base64');
  
          return encoded;
      }catch (ex) {
          return input;
      }
   },
  
  
   decrypt: function (input, password) {
       try{
          // Convert urlsafe base64 to normal base64
          var input = input.replace(/\-/g, '+').replace(/_/g, '/');
          // Convert from base64 to binary string
          var edata = new Buffer(input, 'base64').toString('binary');
  
          // Create key from password
          var m = crypto.createHash('md5');
          m.update(password);
          var key = m.digest('hex');
  
          // Create iv from password and key
          m = crypto.createHash('md5');
          m.update(password + key);
          var iv = m.digest('hex');
  
          // Decipher encrypted data
          var decipher = crypto.createDecipheriv('aes-256-cbc', key, iv.slice(0,16));
          var decrypted = decipher.update(edata, 'binary') + decipher.final('binary');  
          var plaintext = new Buffer(decrypted, 'binary').toString('utf8');
          return plaintext;
       }catch (ex) {
           return input;
       }
    }
  </code></pre>
  
  <p>Please help me to solve this problem.</p>