安全存储
允许访问简单的加密和解密字符串,以便存储在本地机器上。
进程:主进程
此模块保护磁盘上存储的数据不被其他应用程序或拥有完全磁盘访问权的用户访问。
请注意,在Mac上,需要访问系统Keychain,这些调用可以阻止当前线程来收集用户输入。 如果密码管理工具可用,Linux 亦是如此。
方法
safeStorage 模块包含以下方法:
safeStorage.isEncryptionAvailable()
返回 boolean - 加密是否可用
在 Linux 上,如果应用已触发 ready 事件且密钥可用,则返回 true。 在 MacOS 上,如果 Keychain 可用,返回 true。 在 Windows 上,返回 true,应用发出 ready 事件后。
safeStorage.encryptString(plainText)
plainTextstring
返回 Buffer - 一个代表加密字符串的字节数组。
如果加密失败,此函数将抛出错误。
safeStorage.decryptString(encrypted)
encryptedBuffer
返回 string - 解密的字符串。 将使用 safeStorage.encryptString 获得的加密字节数组解密为一个字符串。
解密失败时此函数将抛出错误。
safeStorage.setUsePlainTextEncryption(usePlainText)
usePlainTextboolean
This function on Linux will force the module to use an in memory password for creating symmetric key that is used for encrypt/decrypt functions when a valid OS password manager cannot be determined for the current active desktop environment. This function is a no-op on Windows and MacOS.
safeStorage.getSelectedStorageBackend() Linux
Returns string - User friendly name of the password manager selected on Linux.
This function will return one of the following values:
basic_text- When the desktop environment is not recognised or if the following command line flag is provided--password-store="basic".gnome_libsecret- When the desktop environment isX-Cinnamon,Deepin,GNOME,Pantheon,XFCE,UKUI,unityor if the following command line flag is provided--password-store="gnome-libsecret".kwallet- When the desktop session iskde4or if the following command line flag is provided--password-store="kwallet".kwallet5- When the desktop session iskde5or if the following command line flag is provided--password-store="kwallet5".kwallet6- When the desktop session iskde6.unknown- When the function is called before app has emitted thereadyevent.