How can I convert php code

aes.online-domain-tools.com How can I convert php code

I want to decrypt it like on this site, how can I do it in PHP?

input type : text
input text : hex
fuction : aes
mode : ecb
key : hex

Have a look at https://www.php.net/manual/en/function.openssl-decrypt.php

aes.online-domain-tools.com
I can’t get results like on this site.

You will need to give a lot more information than that if you want people to help you, @bypalermo. What, exactly, are you trying to achieve, and what is the specific problem you are encountering?

Just saying you “can’t get results like on this site” doesn’t really tell us anything.

If I had to give an example

Input type:TXT
Input text (hex): a554754d3907093641e3f02235d661fe97999a2fa085f32ec0a775c0b2c30dc2
Function: AES
Mode : ECB
Key (hex): 9F53074AEED900BAA8C6F4797CD0F7FC

How can I set up a code that can decrypt the above encryption in PHP?

What is your expected output for that input?

“Is it solved now? :)” It has to give the result

Can you please share how you solved for those reading along?

I don’t think they have solved it, I think that’s the string that should come out of the information in post #7.

Ah, right :slightly_smiling_face:

aes.online-domain-tools.com
It can be solved on the site, but I don’t know how to do it in PHP, so I wrote it to learn.

aes.online-domain-tools.com It is solved on the site, how can I solve it in PHP?

@TechnoBear I would be happy if you can help me if you have any information.

See what this does for you.

<?php
// SOURCE:  https://programmer.group/ecb-and-cbc-encryption-and-decryption-of-php7-openssl_decrypt-aes.html
class AES
{
    public $key ;

    public $iv = '1234567890123456';

    public function __construct()
    {
    	$this->key = '1234567890123456';
    }

    public  function decode($str)
    {
        return openssl_decrypt(base64_decode($str),"AES-128-CBC",$this->key,OPENSSL_RAW_DATA, $this->iv);
    }

    public  function encode($str)
    {
        return base64_encode(openssl_encrypt($str,"AES-128-CBC",$this->key,OPENSSL_RAW_DATA, $this->iv));
    }

}

$aes = new AES();
$encryptedMessage = $aes->encode('My Secret Message');

var_dump($encryptedMessage); // '4jZf0a8oV3Xa5e0TyI7EcLAI3FGstD9Hn6teGkzjFIQ=
var_dump($aes->decode($encryptedMessage));//My Secret Message

Thanks, but she couldn’t decipher the encrypted code I gave as an example

<?php
// SOURCE:  https://programmer.group/ecb-and-cbc-encryption-and-decryption-of-php7-openssl_decrypt-aes.html
class AES
{
    public $key ;

    public $iv = 'a554754d3907093641e3f02235d661fe97999a2fa085f32ec0a775c0b2c30dc2';

    public function __construct()
    {
    	$this->key = '9F53074AEED900BAA8C6F4797CD0F7FC';
    }

    public  function decode($str)
    {
        return openssl_decrypt(base64_decode($str),"AES-128-CBC",$this->key,OPENSSL_RAW_DATA, $this->iv);
    }

    public  function encode($str)
    {
        return base64_encode(openssl_encrypt($str,"AES-128-CBC",$this->key,OPENSSL_RAW_DATA, $this->iv));
    }

}

$aes = new AES();
$encryptedMessage = $aes->encode('My Secret Message');

var_dump($encryptedMessage); // '4jZf0a8oV3Xa5e0TyI7EcLAI3FGstD9Hn6teGkzjFIQ=
var_dump($aes->decode($encryptedMessage));//My Secret Message

You gave an example:

But this input text, when translated from hex to ascii, is garbage. You’re telling it your input is ¥TuM9a 6Aãð"5Öaþ—™š/ …ó.À§uÀ²Ã. Â
You then try and use that hex string as the initialization vector, but as the page that you’re trying to duplicate lays out, the initialization vector of an AES encryption is 16 bytes, and you’re giving it 64 (Note that you’re not feeding the hex in, you’re feeding a string in… you might want to employ the hex2bin command, if you want to input hexes.)…so it’s not an IV, it’s not the input text… where’d you get this example from?

The problem isnt in the code that you have been given…

thank you,

On the site I did encryption and decryption

I tried and sent the encrypted code I gave as an example from this site.

How can I do encryption in PHP language code like on this site?

I gave you perfectly good complete working code. How about trying the code first as is and then changing just the message to encode. Also, the code I gave you uses the much more secure CBC instead of ECB.

Just a side note, you might not want to emulate encryption from a site that does not even use an SSL certificate.

1 Like