I am doing a job about using blowfish to encrypt and decrypt in java.
I added a provider and got an instance of "Blowfish / ECB / NoPadding", but I still get this error when I do the encryption.
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
eg:.
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);
leads to
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)
Thanks.
source share