AES encrypt with openssl command line tool, and decrypt in Java

后端 未结 1 2032
遇见更好的自我
遇见更好的自我 2020-12-28 10:25

I have a bash script that uses the openssl tool to encrypt.

#!/bin/bash

key128=\"1234567890123456\"
iv=\"1234567890123456\"
openssl enc -aes-128-cbc -in tes         


        
相关标签:
1条回答
  • 2020-12-28 10:32

    As @Polynomial mentioned above, the keys and iv's don't match between the bash script and Java code. Changing the bash script to the following solves the problem.

    #!/bin/bash
    
    key128="01020304050607080900010203040506"
    iv="01020304050607080900010203040506"
    openssl enc -aes-128-cbc -in test -out test.enc -K $key128 -iv $iv
    

    If openssl is executed in the following way, it will use a password, and print the key and iv used. That key and iv can be substituted in the Java program above.

    openssl enc -nosalt -aes-128-cbc -in test -out test.enc -p
    
    0 讨论(0)
提交回复
热议问题