PHP - 使用 Unix 时间戳作为密钥?
所以,我最近一直在研究加密,我听说有人使用时间戳作为加密密钥。我认为这是一个好主意,但如果我想解密数据,我将如何检索该特定时间戳?时间戳是独一无二的,我不太确定这是如何工作的。
编辑: 我正在使用 PHP 和 MYSQL
So, I've been looking into encryption lately, and I've heard of people using timestamps as keys for encryption. I think this is a great idea, but if I want to decrypt the data, how would I retrieve that specific timestamp? Timestamps are unique, and I'm not really sure how this would work.
EDIT:
I am using PHP and MYSQL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
呃,通常时间戳被用作生成密钥的基础 - 而不是密钥本身。如果您希望能够解密数据,则必须存储密钥以供以后使用。
Er, usually timestamps are used as the basis for generating keys - not as the key itself. The key is something you have to store for later if you want to be able to decrypt the data.
这里有两个问题。
您需要将时间戳存储在某处。那么为什么不直接使用“rand()”并存储它呢。
在现代多线程、多核处理器上有可能获得数百个重复时间戳。所以你也可以只使用 date()。
Two problems here.
You would need to store the timestamp somewhere. So why not just use "rand()" and store that.
Its possible to get hundreds of duplicate timestamps on a modern multi-threaded, multi-core processor. So you may as well just use date().
唯一的方法是保存时间戳。 (假设您的加密没有后门,这会使其目的无效)
我要做的就是以不同的格式保存时间戳以及加密字符串,例如:
09/21/2011 03:09:53 并结合使用 strtotime() 和 salting 将这两个信息位存储在安全的庄园中。
09/21/2011 03:09:53
变为13165--Salt--74593
The only way would be to save the timestamp. (assuming there is no backdoor to your encryption, which would nullify it's purpose)
What I would do is save the timestamp along with the encrypted string in a different format Ex:
09/21/2011 03:09:53
and use a combination ofstrtotime()
and salting to store both bits of information in a secure manor.09/21/2011 03:09:53
becomes13165--Salt--74593
时间戳使得键变得糟糕。一个程序可以在眨眼间就完成所有可能的按键。
组件经常用于启动随机数生成器。但它不能是唯一的组件,因为它不能用作密钥。
该时间可以半成功地用作哈希算法的盐。它仍然不如随机的好,因为它允许攻击者提前生成彩虹表。
Timestamps make awful keys. A program could blaze through all possible keys in the blink of an eye.
The time is often used a component is priming a random number generator. It can't be the only component for the same reason it can't be used as a key, though.
The time could be used semi-successfully as the salt for a hashing algorithm. It's still not as good as something random since it allows the attacker to generate rainbow tables in advance.
我不想伤害你的感情,但是......
很明显你从未研究过加密货币。
因此,请不要设计自己的加密协议,也不要自己组装加密原语(就像“WiFi”设计者/业余密码学家对 WEP 所做的那样)。
旨在满足特定安全目标的协议(我并不是故意说“安全协议”)是由专家发明和实施的。
您首先需要定义您的安全目标,然后选择适当的协议。
I don't want to hurt your feelings, but...
It is very obvious that you have never studied crypto.
So, please do not design your own cryptographic protocols, and do not assemble cryptographic primitives yourself either (like the "WiFi" designers/amateurs cryptologists did with WEP).
Protocols designed to meet specific security goals (I am not saying "secure protocols" on purpose) have been invented and implemented by specialists.
You first need to define your security goals, then choose an adequate protocol.