title: AES/CBC/PKCS5Padding vs AES/CBC/PKCS7Padding with 256 key size performance java
body: <p>I am currently using <code>AES/CBC/PKCS5Padding</code> for encrypting files in Java with <strong>256 bytes</strong> key size, but while searching I found on stackexchange <a href="https://crypto.stackexchange.com/questions/9043/what-is-the-difference-between-pkcs5-padding-and-pkcs7-padding">PKCS#5-PKCS#7 Padding</a> and  it is mentioned,</p>
  
  <blockquote>
    <p>PKCS#5 padding is a subset of PKCS#7 padding for 8 byte block sizes</p>
  </blockquote>
  
  <p>So I want to know  </p>
  
  <ol>
  <li>Will the performance of <code>AES/CBC/PKCS7Padding</code> will be better then <code>AES/CBC/PKCS5Padding</code> for the above configuration?</li>
  <li>How can we configure the block size in Java as it is mentioned
  
  <blockquote>
    <p>PKCS#7 padding would work for any block size from 1 to 255 bytes.</p>
  </blockquote></li>
  </ol>
  
  <p>My sample code is,</p>
  
  <pre><code>SecureRandom rnd = new SecureRandom();
  IvParameterSpec iv = new IvParameterSpec(rnd.generateSeed(16));
  
  KeyGenerator generator = KeyGenerator.getInstance("AES");
  generator.init(256);
  SecretKey k = generator.generateKey();
  
  Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
  c.init(Cipher.ENCRYPT_MODE, k, iv);
  </code></pre>