链接的盐和哈希加密/解密
好的,我有一些链接将通过 php 在我的网站上生成一些广告。现在我遇到的问题只是我理解 md5 是如何工作的,它不是加密,它不能以其最罕见的形式重新呈现......我有一些 mysql id,我想用它们作为选择女巫的数据查询数据库的广告,但我不希望我的用户有权访问广告 ID...所以我希望有人可以向我展示如何在这种情况下使用哈希/盐方法... 请注意:我一直在这个网站上寻找这个答案,我一次又一次地看到人们说盐/散列不是加密,我理解这一点,但如果链接被散列,那么尝试破解我的网站并不那么简单如果它们只是简单的整数。
PHP脚本:
<?
function SuperAd($id){
$sql = mysql_query("SELECT * FROM `ads` WHERE `id`= $id");
while($ad = mysql_fetch_array($sql)){
$title = $ad['title'];
// here is where i want to encrypt
$adlink = $ad['id'];
}
}
?>
ok, so i have some links that will be generated for some ads on my website via php. Now the problem i have is simply i understand how md5 works and it's not an encryption and it can not be re-rendered in its rarest form..... i have some mysql ids that i want to use as the data to select witch ad to query the database for , but i do not want my users to have access to the ads id..... so i was hoping someone could show me how to use the hash/salt method in this case.....
Please note: i have been looking through this site for this answer and i see people time and time again say salt/hash is not encryption i understand that but its not as simple to attempt to hack my site if the links were hashed as they would be if they were just simple integers.
php script:
<?
function SuperAd($id){
$sql = mysql_query("SELECT * FROM `ads` WHERE `id`= $id");
while($ad = mysql_fetch_array($sql)){
$title = $ad['title'];
// here is where i want to encrypt
$adlink = $ad['id'];
}
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

添加盐只是散列的一种更安全的补充。散列只是一种方法。听起来您想要某种方式来加密您的
$ad['id']
,这样用户就不会看到:/viewad/1/
他们看到:
/viewad/12lk3jx09c8faf/
对吗?
只需谷歌一些快速加密/解密算法。
编辑:这是一个可能对您有所帮助的快速问题:
使用 PHP 加密和解密密码的最佳方法?
Adding salt is just a securer addition to hashing. And hashing is one way only. It sounds like you want some way of encrypting your
$ad['id']
, so that instead of users seeing:/viewad/1/
they see:
/viewad/12lk3jx09c8faf/
right?
Just Google for some quick encryption / decryption algorithms.
EDIT: Here is a quick S.O. question that may help you:
Best way to use PHP to encrypt and decrypt passwords?