I am using java bouncycastle to perform encryption.
However, when I encrypt a message, it throws an exception for me.
javax.crypto.IllegalBlockSizeException: data is not aligned by block size
I am using Blowfish / ECB / NoPadding and the message is xml.
public static void main(String args[]){ String message = "<abc>ABCDEFG</abc>"; String key = "key"; byte[] b = encrypt(message.getBytes(), key.getBytes()); } public byte[] encrypt(byte encrypt[], byte en_key[]) { try { SecretKeySpec key = new SecretKeySpec(en_key, "Blowfish"); Cipher cipher = Cipher.getInstance("Blowfish/ECB/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, en_key); return cipher.doFinal(encrypt); } catch (Exception e) { e.printStackTrace(); return null; } }
Can anyone help me?
thanks
source share