在 PHP 中加密整数
我注意到 PHP 中的 openssl 和 mcrypt 函数都只接受要加密为字符串的数据。这意味着 (int)1234567890 的值最初只是一个 4 字节 int,但它被转换并加密为 10 字节字符串。是否有任何加密方法(与 PHP 捆绑或作为外部函数/类)允许对整数进行加密?
I've noticed that both openssl and mcrypt functions in PHP accept data to be encrypted as strings only. This means a value of (int)1234567890 is converted and encrypted as a 10-byte string when it was originally just a 4-byte int. Are there any encryption methods (bundled with PHP or as an external function/class) that allows for the encryption of integers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不可以。如果您想将整数加密为 4 字节二进制表示形式,则必须对其进行预转换:
并且
unpack
解密后再次执行此操作。No. If you want to encrypt your integer as the 4-byte binary representation, then you have to preconvert it:
And
unpack
this again after decryption.mcrypt 对字符串进行操作,而不是整数,因此您需要使用
pack()
好吧,将一个整数打包成一个 4 字节字符串。 (很明显,反函数是unpack()
。)mcrypt operates on strings, not integers, so you'll need to use
pack()
to, well, pack an integer into a 4-byte string. (The inverse function is, sensibly enough,unpack()
.)