117 public static function encrypt(
string $plain_text,
string $key =
null ) {
118 if ($plain_text ===
'') {
125 if (
null === $key || ! is_string( $key ) ) {
126 if ( ! defined(
'XOOPS_SALT' ) ) {
131 $key = substr( md5( $key ), 0, 8 );
149 $crypt_text = openssl_encrypt( $plain_text,
'DES-ECB', $key );
152 return false === $crypt_text ? $plain_text : $crypt_text;
164 public static function decrypt(
string $crypt_text,
string $key =
null ) {
165 if (
'' === $crypt_text ) {
172 if (
null === $key || ! is_string( $key ) ) {
173 if ( ! defined(
'XOOPS_SALT' ) ) {
178 $key = substr( md5( $key ), 0, 8 );
197 $plain_text = openssl_decrypt( $crypt_text,
'DES-ECB', $key, OPENSSL_ZERO_PADDING );
200 $plain_text = rtrim( $plain_text,
"\0" );
202 $pad_ch = substr( $plain_text, - 1 );
203 $pad_len = ord( $pad_ch );
204 if ( 0 == substr_compare( $plain_text, str_repeat( $pad_ch, $pad_len ), - $pad_len ) ) {
205 $plain_text = substr( $plain_text, 0, strlen( $plain_text ) - $pad_len );
208 return false === $plain_text ? $crypt_text : $plain_text;