35 lines
823 B
PHP
35 lines
823 B
PHP
<?php
|
|
namespace Aiko;
|
|
/**
|
|
*
|
|
*/
|
|
class Mycrypt
|
|
{
|
|
private static $output = false;
|
|
private static $encrypt_method = __ENCRYPT_METHOD;
|
|
private static $secret_key = __SECRET_KEY;
|
|
private static $secret_iv = __SECRET_IV;
|
|
|
|
private function __construct(){}
|
|
|
|
public static function encrypt($string)
|
|
{
|
|
$key = hash('sha256', self::$secret_key);
|
|
$iv = substr(hash('sha256', self::$secret_iv), 0, 16);
|
|
self::$output = openssl_encrypt($string, self::$encrypt_method, $key, 0, $iv);
|
|
return base64_encode(self::$output);
|
|
}
|
|
|
|
public static function decrypt($string)
|
|
{
|
|
$key = hash('sha256', self::$secret_key);
|
|
$iv = substr(hash('sha256', self::$secret_iv), 0, 16);
|
|
return openssl_decrypt(base64_decode($string), self::$encrypt_method, $key, 0, $iv);
|
|
}
|
|
|
|
private function __destruct(){}
|
|
}
|
|
|
|
|
|
|
|
?>
|