gpt4 book ai didi

javascript - WebCrypto API 在哪里存储 key ?

转载 作者:数据小太阳 更新时间:2023-10-29 06:04:41 27 4
gpt4 key购买 nike

我正在使用 webcrypto API 成功地加密服务器和客户端之间的消息(假设我需要手动执行此操作)。

我的问题是我需要检查用户和服务器的 key 对是否已经存在,而不是一直生成新的 key 对。有没有办法检查它是否存在并检索它以解密服务器消息?

澄清一下,我的 privateKey 在浏览器上,publicKey 被发送到服务器。

我有一个 nodejs 服务器和纯 JS 前端。

提前致谢。

最佳答案

默认情况下,加密 key 不是永久性的。您需要将键存储在 IndexedDB 中,以便下次浏览器执行时可以使用它们。

IndexedDB是一个安全存储, key 可以在不暴露 key Material 的情况下存储、恢复和使用

参见 https://www.w3.org/TR/WebCryptoAPI/#concepts-key-storage

5.2. Key Storage

This specification does not explicitly provide any new storage mechanisms for CryptoKey objects. Instead, by allowing the CryptoKey to be used with the structured clone algorithm, any existing or future web storage mechanisms that support storing structured clonable objects can be used to store CryptoKey objects.

In practice, it is expected that most authors will make use of the Indexed Database API, which allows associative storage of key/value pairs, where the key is some string identifier meaningful to the application, and the value is a CryptoKey object. This allows the storage and retrieval of key material, without ever exposing that key material to the application or the JavaScript environment

这里有一个完整的例子 https://blog.engelke.com/2014/09/19/saving-cryptographic-keys-in-the-browser/

关于javascript - WebCrypto API 在哪里存储 key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49478240/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com