PHP 使用 HTML keygen 公钥加密返回
如何使用从 HTML5 的 keygen 获得的公钥在 PHP 中加密任何内容?有标准函数吗?
提前致谢!
How can I encrypt - anything - within PHP with the public key I get from HTML5's keygen? Is there a standard function for that?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
选择的答案绝对不正确!
如果您使用keygen元素生成对称加密密钥,它将首先否定使用加密提供的任何保护。
通过不安全的通道发送对称加密密钥是使用密码学的首要规则之一。私钥就是这样,私人的。此外,公钥不应该用作加密密码,如果它是 RSA 密钥类型,它可以用于加密数据和/或验证数据。
keygen 元素应用于生成签名的公钥和密钥。首先创建一个私钥(RSA),浏览器注册并使用它来提供基于证书的身份验证。
要进一步研究确认此答案,请参阅以下参考文献:
The answer selected is absolutely incorrect!
If you are using the keygen element to generate a symmetric encryption key, it will negate any protections offered by using encryption in the first place.
Sending a symmetric encryption key over an insecure channel is one the first rules of using cryptography. Private keys are just that, private. What's more a public key should not be used as an encryption password, it can be used to encrypt data and/or verify data if it is an RSA keytype.
The keygen element should be used to generate a signed public key & challenge by first creating a private key (RSA) which gets registered and used by the browser to provide certificate based authentication.
For further research confirming this answer please see the following references:
生成签名的公钥,也称为 SPKAC。据我所知,使用它们的唯一简单方法是使用 phpseclib,一个纯 PHP SPKAC 实现。例如。
generates signed public keys, also known as SPKACs. The only easy way I know of to use them is to use phpseclib, a pure PHP SPKAC implementation. eg.
您可以使用 PHP 中提供的 mcrypt 函数(如果您的服务器上有可用的库扩展) - 例如
您的 HTML 表单有一个字段:
您的PHP 可以执行以下操作:(未测试)
有关 mcrypt 的更多信息,请参阅: https://www.php.net/manual/en/book.mcrypt.php
You can use the mcrypt functions available in PHP (if you have the library extension available on your server) - for example
Your HTML Form has a field:
<keygen name="mykey" />
Your PHP could do something like: (not tested)
For more on mcrypt see: https://www.php.net/manual/en/book.mcrypt.php