Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PHP OpenSSL AES-256-CBC different output

I’m using this code to encrypt:

    $content='Hello World';
            
    $output = openssl_encrypt(
        $content,
        'AES-256-CBC',
        '2EE3732CA11BAD106A2429C142136345',
        OPENSSL_RAW_DATA,
        $iv
    );
            
    echo bin2hex($output);

And my output is: bc08212ff2960c50327e4f1585f401b9

But when I use this website https://www.javainuse.com/aesgenerator, my output is:
5415dc0f7cc496be97f2dc9b9d5b2b42

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

I need this output 5415dc0f7cc496be97f2dc9b9d5b2b42 on my code output.
Because in java programming language I get this result.

        String text="Hello World";

        String secretKey="2EE3732CA11BAD106A2429C142136345";

        IvParameterSpec ivParameterSpec = new IvParameterSpec("0000000000000000".getBytes());
        SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), "AES");
        Cipher instance = Cipher.getInstance("AES/CBC/PKCS5Padding");
        instance.init(1, secretKeySpec, ivParameterSpec);
        String output= stringToHex(instance.doFinal(text.getBytes()));

        System.out.println(output); //Output: 5415dc0f7cc496be97f2dc9b9d5b2b42

>Solution :

Call the function with ..,$iv = ‘0000000000000000’).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading