Skip to main content

safeStorage

Allows access to simple encryption and decryption of strings for storage on the local machine.允许访问用于存储在本地计算机上的字符串的简单加密和解密。

Process:进程:Main

This module protects data stored on disk from being accessed by other applications or users with full disk access.此模块保护存储在磁盘上的数据不被其他具有完全磁盘访问权限的应用程序或用户访问。

Note that on Mac, access to the system Keychain is required and these calls can block the current thread to collect user input. 请注意,在Mac上,需要访问系统钥匙链,这些调用可以阻止当前线程来收集用户输入。The same is true for Linux, if a password management tool is available.如果有密码管理工具,Linux也是如此。

Methods方法

The safeStorage module has the following methods:safeStorage模块有以下方法:

safeStorage.isEncryptionAvailable()

Returns返回boolean - Whether encryption is available.加密是否可用。

On Linux, returns true if the app has emitted the ready event and the secret key is available. 在Linux上,如果应用程序已发出ready事件并且密钥可用,则返回trueOn MacOS, returns true if Keychain is available. 在MacOS上,如果Keychain可用,则返回trueOn Windows, returns true once the app has emitted the ready event.在Windows上,一旦应用程序发出ready事件,就会返回true

safeStorage.encryptString(plainText)

  • plainText string

Returns返回Buffer - An array of bytes representing the encrypted string.表示加密字符串的字节数组。

This function will throw an error if encryption fails.如果加密失败,此函数将引发错误。

safeStorage.decryptString(encrypted)

  • encrypted Buffer

Returns返回string - the decrypted string. 解密后的字符串。Decrypts the encrypted buffer obtained with safeStorage.encryptString back into a string.将使用safeStorage.encryptString获得的加密缓冲区解密回字符串。

This function will throw an error if decryption fails.如果解密失败,此函数将抛出一个错误。