基本上,我的想法是在PHP中引入一个计时结构,让我们说每隔N天改变一次系统的主加密算法。
$key32 = pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3"); # 32 byte
$key24 = pack('H*', "dd0255b51151b71427984aa74ae4f1993b7400c3d184ad02"); # 24 byte
$key16 = pack('H*', "13196c5ecdac5413148ba11469448474"); # 16 byte
# show key size use either 16, 24 or 32 byte keys for AES-128, 192
# and 256 respectively
$key_size = strlen($key24);
echo "Key size: " . $key_size . "\n";
$plaintext = "Ruffles";
# create a random IV to use with CBC encoding
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_192, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
# creates a cipher text compatible with AES (Rijndael block size = 128)
# to keep the text confidential
# only suitable for encoded input that never ends with value 00h
# (because of default zero padding)
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_192, $key24,
$plaintext, MCRYPT_MODE_CBC, $iv);
# prepend the IV for it to be available for decryption
$ciphertext = $iv . $ciphertext;
# encode the resulting cipher text so it can be represented by a string
$ciphertext_base64 = base64_encode($ciphertext);
虽然做了这样的事情:
if (date('d.m.y')=='08.11.14') {
$encryption = 'MCRYPT_RIJNDAEL_192';
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key24,
$plaintext, MCRYPT_MODE_CBC, $iv);
}
无法解决问题,因为该文件必须在该日期加载,此外,该文件应该只是加密用户密码以便以后直接插入数据库。我应该做一个cron工作吗?