0

I dont can change Key or IV, only in this case the encryption does work in Java and Linux.

Linux:

echo  -n 1234567890ABCDEF| openssl enc -bf-cbc  -K 0  -iv 0 -nopad -nosalt |base64 

Java

byte[] key = {0};

byte[] iv = {0, 0, 0, 0, 0, 0, 0, 0};

Cipher c = Cipher.getInstance("BlowFish/CBC/NoPadding");
Key k = new SecretKeySpec(key, "BlowFish");
c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));

byte[] encrypt = c.doFinal("1234567890ABCDEF".getBytes("UTF-8"));

System.out.println(new String(Base64.encodeBase64(encrypt)));

How to change Key and IV and so both continue equals?

Wender
  • 991
  • 15
  • 24
  • So, what's the exception that you get on the Java side? I think it should be precise enough to tell you how long the key must be. – Artjom B. Oct 21 '16 at 21:21
  • 1
    BlowFish really should not be used in new work, even the author uses AES. You should use a random IV, just prefix the encrypted data with it for use during decryption. If you use no padding the imput length to be encrypted must be an exact multiple of the block size, you might need to use PKCS#5 padding. You are doing encryption for security, right? – zaph Oct 21 '16 at 21:34
  • I believe you are being tripped up on [`EVP_BytesToKey`](https://www.openssl.org/docs/manmaster/crypto/EVP_BytesToKey.html). Also see [Java openssl encryption / decryption key generation](http://stackoverflow.com/q/34502705), [Java equivalent of an OpenSSL AES CBC encryption](http://stackoverflow.com/q/32508961) and friends. Once you know what to look for, you can find it all over the web. – jww Oct 22 '16 at 12:26

1 Answers1

2

Read the documentation:

All the block ciphers normally use PKCS#5 padding also known as standard block padding

Since your Java code says NoPadding, you'd want to add an extra argument:

-nopad
     disable standard block padding
Andreas
  • 154,647
  • 11
  • 152
  • 247
  • Sorry, I forgot to write "-nopad". So this is the case if I try to change IV or Key the results don't match – Wender Oct 24 '16 at 10:08