How to solve javax.crypto.IllegalBlockSizeException: data not block size aligned
<p>I am doing an assignment about use blowfish to do encryption &amp; decryption in java.</p>

<p>I had added a provider, and get instance "Blowfish/ECB/NoPadding", but I still get this error when I do the encryption. </p>

<pre><code>Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
</code></pre>

<p>e.g.:</p>

<pre><code>public static byte[] encrypt(byte to_encrypt[], byte strkey[]) {
    try {           
        SecretKeySpec key = new SecretKeySpec(strkey, "Blowfish");
        Cipher cipher = Cipher.getInstance("Blowfish/ECB/NoPadding");
        cipher.init(Cipher.ENCRYPT_MODE, key);  
        return cipher.doFinal(to_encrypt); // &lt;=========== error
    } catch (Exception e) { 
        e.printStackTrace();
        return null; 
    }
}
</code></pre>

<p>leads to</p>

<pre><code>javax.crypto.IllegalBlockSizeException: data not block size aligned
    at org.bouncycastle2.jce.provider.JCEBlockCipher.engineDoFinal(JCEBlockCipher.java:686)
    at javax.crypto.Cipher.doFinal(Cipher.java:1171)
</code></pre>

<p>Thank you.</p>
