简体   繁体   English

如何使用html5生成临时公钥

[英]How to generate temporary public-key using html5

How to generate a public/private key pair in the user's browser, 如何在用户的浏览器中生成公钥/私钥对,

This key must be: 这个密钥必须是:

  • temporary (not saved for ever, valid only for the current session). 临时(不会永久保存,仅对当前会话有效)。
  • generated in a cross browser/system manner without prompting the user for any input. 以跨浏览器/系统方式生成,而不提示用户输入任何内容。
  • allow access to the public key's hash for validation purposes. 允许访问公钥的哈希以进行验证。

I tried using <keygen> but it requires using forms and user intervention. 我尝试使用<keygen>但它需要使用表单和用户干预。

Consider using WebCrypto 考虑使用WebCrypto

Specifically, crypto.subtle.generateKey will do the key generation. 具体来说, crypto.subtle.generateKey将执行密钥生成。

  • The key can be temporary as long as you discard it securely and/or invalidate it after its desired validity period has expired. 只要您在所需的有效期到期后安全地丢弃和/或使其无效,密钥就可以是临时密钥。 Depending on how your system works, you may want to validate the expiry/validity of a given key by rolling it into the hash. 根据系统的工作方式,您可能希望通过将其滚动到散列中来验证给定密钥的到期/有效性。

  • Here is a tutorial which offers a cross-browser solution. 这是一个提供跨浏览器解决方案的教程

  • Hashing the key (and/or other data) can be done using other parts of the WebCrypto API (see crypto.subtle.digest ) 散列密钥(和/或其他数据)可以使用WebCrypto API的其他部分来完成(请参阅crypto.subtle.digest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM