برای رمزنگاری از تابع زیر استفاده کنید :

 

function EncryptString($string)

{

    try {

        $ciphering = "AES-128-CTR";

        $iv_length = openssl_cipher_iv_length($ciphering);

        $options = 0;

        $iv = "1234567890123456";

        $key = "1234567890123456";

        $result = openssl_encrypt($string,$ciphering,$key,$options,$iv);

        return $result;

 

    } catch (\Throwable $th) {

        // return $th->getMessage();

        return false;

    }

 

}

 

 

 

 

برای رمزگشایی هم از تابع زیر استفاده کنید :

 

 

function DecryptString($string)

{

    try {

        $ciphering = "AES-128-CTR";

        $iv_length = openssl_cipher_iv_length($ciphering);

        $options = 0;

        $iv = "1234567890123456";

        $key = "1234567890123456";

        $result = openssl_decrypt($string,$ciphering,$key,$options,$iv);

        return $result;

 

    } catch (\Throwable $th) {

        return false;

    }

 

}