title: How to decrypt password from JavaScript CryptoJS.AES.encrypt(password, passphrase) in Python
body: <p>I have a password which is encrypt from JavaScript via</p>
  
  <pre class="lang-js prettyprint-override"><code>  var password = 'sample'
    var passphrase ='sample_passphrase'
    CryptoJS.AES.encrypt(password, passphrase)
  </code></pre>
  
  <p>Then I tried to decrypt the password comes from JavaScript in Python:</p>
  
  <pre class="lang-py prettyprint-override"><code>  from Crypto.Cipher import AES
    import base64
  
    PADDING = '\0'
  
    pad_it = lambda s: s+(16 - len(s)%16)*PADDING
    key = 'sample_passphrase'
    iv='11.0.0.101'        #------&gt; here is my question, how can I get this iv to restore password, what should I put here?
    key=pad_it(key)        #------&gt; should I add padding to keys and iv?
    iv=pad_it(iv)          ##
    source = 'sample'
    generator = AES.new(key, AES.MODE_CFB,iv)
    crypt = generator.encrypt(pad_it(source))
    cryptedStr = base64.b64encode(crypt)
    print cryptedStr
    generator = AES.new(key, AES.MODE_CBC,iv)
    recovery = generator.decrypt(crypt)
    print recovery.rstrip(PADDING)
  </code></pre>
  
  <p>I checked JS from browser console, it shows IV in <code>CryptoJS.AES.encrypt(password, passphrase)</code> is a object with some attributes( like <code>sigBytes:16, words: [-44073646, -1300128421, 1939444916, 881316061]</code>). It seems generated randomly. </p>
  
  <p>From one web page, it tells me that JS has two way to encrypt password 
  (<a href="http://www.cnblogs.com/Lifehacker/p/nodejs_aes_encrypt_problem.html" rel="noreferrer">reference link</a> ):</p>
  
  <blockquote>
    <ul>
    <li>a. <code>crypto.createCipher(algorithm, password)</code></li>
    <li>b. <code>crypto.createCipheriv(algorithm, key, iv)</code></li>
    </ul>
  </blockquote>
  
  <p>What I saw in JavaScript should be option a. However, only option b is equivalent to AES.new() in python.</p>
  
  <p><strong>The questions are</strong>:</p>
  
  <ol>
  <li><p>How can I restore this password in Python without changing JavaScript code? </p></li>
  <li><p>If I need IV in Python, how can I get it from the password that is used in JavaScript? </p></li>
  </ol>