rafrsr/crypto

PHP中简单加密和解密字符串。

2.1.4 2019-09-12 16:53 UTC

This package is auto-updated.

Last update: 2024-09-13 03:35:50 UTC


README

Build Status Coverage Status Latest Stable Version Latest Unstable Version Total Downloads License

PHP中简单加密和解密字符串。

特性

  • 简单使用 Crypto::build('secretKey')->encrypt('secret message')
  • 支持最流行的MCRYPT算法
  • 通过isEncrypted($data)方法进行加密验证
  • 防止重复加密/解密

用法

use Rafrsr\Crypto\Crypto;

$encryptor = Crypto::build('JH83UN177772JJASHGAGG38UABASDSD');
//$encryptor = Crypto::build('JH83UN177772JJASHGAGG38UABASDSD', MCRYPT_RIJNDAEL_128); //using specific algorithm

$secret = $encryptor->encrypt('This is a secret message');

if ($encryptor->isEncrypted($secret)) {
    echo 'The messages is encrypted';
}

$notSecret = $encryptor->decrypt($secret);

if (!$encryptor->isEncrypted($notSecret)) {
    echo 'The message is not encrypted';
}