title: RSA/ECB/PKCS1 Padding & AES/CBC/PKCS5Padding Encryption / Decryption
body: <p>I have an API to call where I have to encrypt my data using RSA/ECB/PKCS1 Padding &amp; AES/CBC/PKCS5PADDING.</p>
  
  <pre><code>Sample Data: {"KEY":"VALUE"}
  </code></pre>
  
  <p>Step.1: </p>
  
  <pre><code>I have to generate a random number of 16 digit. eg: '1234567890123456'
  </code></pre>
  
  <p>Step.2: </p>
  
  <pre><code>Do RSA/ECB/PKCS1Padding to random number and base64Encode the result. we get "encrypted_key"
  </code></pre>
  
  <p>Step.3: </p>
  
  <pre><code>Concatenate random number &amp; data:
  DATA = 1234567890123456{"KEY":"VALUE"}
  </code></pre>
  
  <p>Step.4: </p>
  
  <pre><code>Do AES/CBC/PKCS5Padding on DATA (from Step 3) using random number(1234567890123456) as KEY &amp; Base64Encoded random number as IV. we get "ENCRYPTED_DATA"
  </code></pre>
  
  <p>So, for <strong>Step 1</strong> I am using <code>JSEncrypt</code> javascript library.
  for <strong>Step 4</strong> I am using <code>CrytoJS.AES.encrypt()</code> function. I am pretty sure that my JSEncrypt function is running fine as the client is able to decrypt it but client is not able to decrypt my data. I feel that I am making a mistake while using <code>CryptoJS</code>.</p>
  
  <p>Can someone guide me properly on how to use the library.</p>
  
  <p>What I am doing is:</p>
  
  <pre><code>KEY =  '1234567890123456'
  IV  = MTIzNDU2Nzg5MDEyMzQ1Ng==  (result of btoa('1234567890123456') )
  DATA = "1234567890123456{"KEY":"VAL"}"
  
  cryptedData = Crypto.AES.encrypt(DATA, KEY, {iv: IV, mode: CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7})
  </code></pre>
  
  <p>I am told to use <code>PKCS5Padding</code> in AES/CBC Encryption ( Step 4 ) but it seems that <code>AES</code> does not support <code>PKCS5Padding</code> but <code>PKCS7Padding</code>. </p>
  
  <p>I think I am making a mistake in the way I am passing KEY &amp; IV to <code>CryptoJS</code>.</p>
  
  <p>Any help will be greatly appreciated.</p>