Re: Emulate openssl_decrypt PHP on command line

Tomas Mraz <[email protected]> Wed, 11 Feb 2026 10:24:32 +0100
Newsgroups gmane.comp.encryption.openssl.user
Message-ID <[email protected]>
Hello,

you can try using -K option instead of -pass with `enc`. That requires
converting the key to hexadecimal. BTW, the encryption key should be
256 bits long if it is an AES-256 key.

Tomas Mraz, OpenSSL


On Wed, 2026-02-11 at 00:36 -0800, Avelino Herrera Morales wrote:
> Hi all,
> 
> I have a very simple code in PHP to decrypt an AES-256-ECB stream in
> PHP that runs ok:
> 
> $ticketKeyEncHex =
> "3752B8D2A9BBA61682C7E93710DE9527F6C919E0E9678E4BC87C7809E34D5750";
> $clientSecret = "666f3_SOME_HEX_HERE_4d4a";
> $ticketKeyEncBin = hex2bin($ticketKeyEncHex);
> $ret = openssl_decrypt($ticketKeyEncBin, "aes-256-ecb",
> $clientSecret, OPENSSL_RAW_DATA);    // returns a correct decrypted
> string
> 
> But I do no know how to replicate that call on command line. The
> following command does not generate the same decrypted string:
> 
> $ echo -n
> "3752B8D2A9BBA61682C7E93710DE9527F6C919E0E9678E4BC87C7809E34D5750" |
> xxd -r -ps | openssl enc -d -aes-256-ecb -nosalt -pass
> pass:666f3_SOME_HEX_HERE_4d4a -pbkdf2 -nopad | hexdump -C
> 
> How do I replicate the openssl_decrypt call in cli?
> 
> Thanks!
> -- 
> You received this message because you are subscribed to the Google
> Groups "openssl-users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to openssl-users+unsubscribe-MCmKBN63+Bmbup2nOX2J7Q@public.gmane.org
> To view this discussion visit
> https://groups.google.com/a/openssl.org/d/msgid/openssl-users/dcfd89f6-2a7f-4fdf-8285-820fd3b864a3n%40openssl.org
> .

-- 
Tomáš Mráz, Chief Technology Officer, OpenSSL Foundation
Join the Code Protectors or support us on Github Sponsors
https://openssl-foundation.org/donate/

-- 
You received this message because you are subscribed to the Google Groups "openssl-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openssl-users+unsubscribe-MCmKBN63+Bmbup2nOX2J7Q@public.gmane.org
To view this discussion visit https://groups.google.com/a/openssl.org/d/msgid/openssl-users/b176c2f685a4eecf8a60ef0d8966461e6215d890.camel%40openssl.org.