md5加密解密


md5 encryption decryption

我的数据库表中有一个名为download_key的字段。它通常保存在表中,不进行加密。我将此密钥作为表单中的隐藏值发送。如果有人右键单击页面并查看页面的源,则该密钥是可见的。是否可以仅在视图中对其进行加密?我还将密钥的隐藏值和数据库中存储的值进行了比较。

某些代码

控制器

$query = $this->db->get_where('mc_boxes', array('idmc_boxes' => $id));
$row = $query->row();
$data['download_key'] = strtolower($row->downloadkey);

在我的视图内部

<form name="form" method="post" onsubmit="return validateForm('<?php echo $download_key ?>')"> 
    <input type="hidden" name="key" value="<?php echo $download_key ?>" />
</form>

有加密/解密功能可用-请查看http://codeigniter.com/user_guide/libraries/encryption.html

$msg = 'My secret message';
$key = 'super-secret-key';
$encrypted_string = $this->encrypt->encode($msg, $key);
$encrypted_string = 'APANtByIGI1BpVXZTJgcsAG8GZl8pdwwa84';
$plaintext_string = $this->encrypt->decode($encrypted_string);

看看这对你的情况是否有帮助。:)

为什么不使用会话?

$_SESSION['DL_KEY'] = strtolower($row->downloadkey);

并且将不需要以

的形式对其进行回声

尝试使用带密钥的可反转加密(这将仅在您的配置中,对其他人隐藏)。

$key = 'YOUR_UNIQUE_KEY_HERE';
$phrase = 'PHRASE_TO_DECODE_OR_ENCODE';
if ($method == 'encode')
    return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $phrase, MCRYPT_MODE_ECB, mcrypt_create_iv(32, MCRYPT_RAND)));
else if ($method == 'decode')
    return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($phrase), MCRYPT_MODE_ECB, mcrypt_create_iv(32, MCRYPT_RAND)));

查看函数md5。它是一个原生php函数。与代码点火器无关。

string md5 ( string $str [, bool $raw_output = false ] )是函数签名。

以如下形式打印密钥:

    echo $this->encrypt->encode($download_key); 

然后,在将其插入数据库之前,请执行以下操作:

    $download_key = $this->encypt->decode($download_key);