how to use OpenSSL to decrypt Java AES-encrypted data?

前端 未结 3 826
说谎
说谎 2021-01-03 15:03

I\'m interfacing to a legacy Java application (the app cannot be changed) which is encrypting data using AES. Here is how the original Java code is instantiating the AES ci

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-03 15:19

    Possible answer found:

    "By default, Java Ciphers (at least in Sun's implementations) are constructed in what is called Electronic Codebook (ECB) mode." (Source: http://www.javamex.com/tutorials/cryptography/block_modes.shtml)

    So if ECB is used by default, I guess that means no initialization vector, and I can use the following method from OpenSSL:

    void AES_ecb_encrypt(*in, *out, *key, enc);
    

    Using AES_decrypt() I can decrypt 1000+ byte messages that originated on the Java side. So it looks like Java does indeed default to ECB mode with no initialization vector. However, I still cannot encrypt and send a new message to the Java app. Investigation continues.


    Got it all working. Thanks for the numerous hints. I can confirm Java uses ECB by default. All padding bytes are set to the number of bytes added (which is known as PKCS5-padding). "Hello World" -> encrypted by Java -> decrypted using OpenSSL will look like "Hello World\5\5\5\5\5".

提交回复
热议问题