zeyon/cryptastic

使用MCrypt库进行PHP加密/解密。

1.0 2014-10-17 12:50 UTC

This package is not auto-updated.

Last update: 2024-09-24 02:01:31 UTC


README

这是Andrew Johnson的cryptastic类的修改版

原始代码可以在以下URL找到

http://www.itnewb.com/v/PHP-Encryption-Decryption-Using-the-MCrypt-Library-libmcrypt

示例

$pass = 'the password';
$salt = 'the password salt';
$msg  = 'This is the secret message.';

/**********************************************************************************************************************/

// EXAMPLE #1 USING STRING AS MESSAGE

$cryptastic = new cryptastic;

$key = $cryptastic->pbkdf2($pass, $salt, 1000, 32) or
	die("Failed to generate secret key.");

$encrypted = $cryptastic->encrypt($msg, $key) or
	die("Failed to complete encryption.");

$decrypted = $cryptastic->decrypt($encrypted, $key) or
	die("Failed to complete decryption");

echo $decrypted . "<br /><br />\n";

/**********************************************************************************************************************/

// EXAMPLE #2 USING ARRAY AS MESSAGE

$msg        = array('message' => $msg);
$encrypted  = $cryptastic->encrypt($msg, $key);
$decrypted  = $cryptastic->decrypt($encrypted, $key);

echo $decrypted['message'];