在PHP中需要一个简单的哈希 [英] Need a simple hash in PHP
问题描述
我需要创建一个简单的哈希方法来传递URL中的一些数据。它不需要非常安全,这对大多数人来说不是很明显。
I need to create a simple hashing method for passing some data in a URL. It doesn't need to be very secure, it just shouldn't be obvious to most people.
哈希需要包含发件人和ID的数字ID的收件人,我应该能够在阅读附加的散列后对数据进行解码。
The hash needs to contains the numerical id of the sender and the id of the recipient and I should be able to decode the data after reading the appended hash.
任何想法?我希望哈希尽可能简短,只是因为这个URL是通过IM,电子邮件等共享的。
Any ideas? I'd like the hash to be a short as possible, simply because this url is meant to be shared via IM, email, etc..
推荐答案
哈希只是一种方式。如果你想解密它,你必须加密它。尝试 mcrypt 与其中之一。
Hash is one way only. If you want to decrypt it, you have to encrypt it. Try mcrypt with one of these.
对于非安全的东西,您可以尝试<一个href =http://php.net/manual/en/function.base64-encode.php =nofollow noreferrer> base64_encode ,你也可以 base_convert 每个数字标识从10到36位数字左右。将数字乘以秘密常数也可以帮助。
For non secure stuff you can try base64_encode, You can also base_convert each numeric id from 10 to 36 digits or so. Multiplying the numbers with a secret constant could also help.
$obscurity = base_convert($recipientId * 42, 10, 36) . ':' . base_convert($senderId * 42, 10, 36)
这篇关于在PHP中需要一个简单的哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!