encriptar id php ejemplo encrypt y decrypt
Tue Feb 10 2026 19:43:38 GMT+0000 (Coordinated Universal Time)
Saved by
@jrg_300i
<?php
namespace App\Helpers;
use Config;
use Str;
class Encryptor
{
public static function method()
{
return Config::get('app.cipher');
}
public static function hash_key()
{
return hash('sha256', Str::substr(Config::get('app.key'), 7));
}
public static function iv()
{
$secret_iv = Str::substr(Config::get('app.key'), 7);
$iv = substr(hash('sha256', $secret_iv), 0, 16);
return $iv;
}
public static function encrypt($value)
{
$output = openssl_encrypt($value, self::method(), self::hash_key(), 0, self::iv());
$output = base64_encode($output);
return $output;
}
public static function decrypt($value)
{
$output = openssl_decrypt(base64_decode($value), self::method(), self::hash_key(), 0, self::iv());
return $output;
}
}
content_copyCOPY
Comments