简体   繁体   English

md5加密解密

[英]md5 encryption decryption

I have a field in my database table with the name download_key. 我的数据库表中有一个名为download_key的字段。 It is saved normally in the table no encryption is done. 它通常保存在表中,不进行加密。 I am sending this key as hidden value in the form. 我将此密钥作为隐藏值发送到表单中。 If someone right click on the page and view the source of page the key is visible. 如果有人右键单击页面并查看页面源,则可以看到该键。 Is it possible to encrypt it in the view only? 是否可以仅在视图中加密它? I am also comparing the hidden value of the key with the one stored in database. 我还将密钥的隐藏值与存储在数据库中的密钥进行比较。

Some code 一些代码

Controller 调节器

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

Inside my view 在我看来

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

Why don't you use sessions? 你为什么不用会话?

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

and there will not be necessarry to echo it in the form 并且没有必要在表格中回应它

Try using reversable encryption with key (that will be only in your config, hidden from anyone else). 尝试使用带密钥的可逆加密(仅在您的配置中,对其他任何人隐藏)。

$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)));

There are Encryption/Decryption functions available - please have a look at http://codeigniter.com/user_guide/libraries/encryption.html 有加密/解密功能 - 请查看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);

See if this helps in your case. 看看这对您的情况是否有帮助。 :) :)

Look at function md5 . 看看功能md5 It is a native php function. 这是一个原生的PHP功能。 Has nothing to do with codeigniter. 与codeigniter无关。

string md5 ( string $str [, bool $raw_output = false ] ) is the function signature. string md5 ( string $str [, bool $raw_output = false ] )是函数签名。

Print your key in the form like this: 在以下表格中打印您的密钥:

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

Then, before it gets inserted into the database, do this: 然后,在将其插入数据库之前,执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM