safeStorage
文字列をローカルマシンに保管するにあたって簡単な暗号化と復号へのアクセスを可能にします。
プロセス: Main
This module adds extra protection to data being stored on disk by using OS-provided cryptography systems. Current security semantics for each platform are outlined below.
- macOS: Encryption keys are stored for your app in Keychain Access in a way that prevents other applications from loading them without user override. Therefore, content is protected from other users and other apps running in the same userspace.
- Windows: Encryption keys are generated via DPAPI. As per the Windows documentation: "Typically, only a user with the same logon credential as the user who encrypted the data can typically decrypt the data". Therefore, content is protected from other users on the same machine, but not from other apps running in the same userspace.
- Linux: Encryption keys are generated and stored in a secret store that varies depending on your window manager and system setup. Options currently supported are
kwallet
,kwallet5
,kwallet6
andgnome-libsecret
, but more may be available in future versions of Electron. As such, the security semantics of content protected via thesafeStorage
API vary between window managers and secret stores.- Note that not all Linux setups have an available secret store. If no secret store is available, items stored in using the
safeStorage
API will be unprotected as they are encrypted via hardcoded plaintext password. You can detect when this happens whensafeStorage.getSelectedStorageBackend()
returnsbasic_text
.
- Note that not all Linux setups have an available secret store. If no secret store is available, items stored in using the
なお、Mac ではシステムのキーチェーンへのアクセスが必要であり、これらの呼び出しがユーザ入力の収集のために現在のスレッドをブロックすることがあります。 パスワード管理ツールが利用可能な場合、Linux でも同じことが言えます。
メソッド
safeStorage
モジュールには以下のメソッドがあります。
safeStorage.isEncryptionAvailable()
戻り値 boolean
- 暗号化が利用可能かどうか。
Linux では、app で ready
イベントが発生し、かつ秘密鍵が利用可能である場合は true を返します。 MacOS では、キーチェーンが利用可能な場合は true を返します。 Windows では、アプリで ready
イベントが発生した以降は true を返します。
safeStorage.encryptString(plainText)
plainText
string
戻り値 Buffer
- 暗号化した文字列を表すバイトの配列。
この関数は、暗号化に失敗するとエラーを送出します。
safeStorage.decryptString(encrypted)
encrypted
Buffer
戻り値 string
- 復号した文字列。 safeStorage.encryptString
で得た暗号化されたバッファを、文字列に復号します。
この関数は、復号に失敗するとエラーを送出します。
safeStorage.setUsePlainTextEncryption(usePlainText)
usePlainText
boolean
Linux でのこの関数は、現在のアクティブなデスクトップ環境に対して有効な OS のパスワードマネージャーを決定できない場合、モジュールがインメモリのパスワードを使って暗号化/復号関数で使用する共通鍵を作成させます。 この関数は Windows と macOS では何もしません。
safeStorage.getSelectedStorageBackend()
Linux
戻り値 string
- Linux で選択されたパスワードマネージャーのユーザーフレンドリーな名前。
この関数は以下のいずれかの値を返します。
basic_text
- デスクトップ環境が認識されない場合、または次のコマンドラインフラグで--password-store="basic"
が指定されている場合。gnome_libsecret
- デスクトップ環境がX-Cinnamon
,Deepin
,GNOME
,Pantheon
,XFCE
,UKUI
,unity
の場合、または以下のコマンドラインフラグで--password-store="gnome-libsecret"
が指定されている場合。kwallet
- デスクトップセッションがkde4
の場合、または次のコマンドラインフラグで--password-store="kwallet"
が指定された場合。kwallet5
- デスクトップセッションがkde5
の場合、または次のコマンドラ���ンフラグで--password-store="kwallet5"
が指定された場合。kwallet6
- デスクトップセッションがkde6
の場合。unknown
- アプリがready
イベントを発行する前に関数が呼び出されたとき。