问题
My Firefox extension needs to;
- store user credentials in a file that will be stored in users local filesystem.
- when credentials are needed, decrypt file read values and encrypt it again.
- sometimes send encrypted file over http to a server.
I cant find any XPCOM component to encrypt / decrypt a file. Should i write my own XPCOM object, or is there any other reasonable solution for that.
[Note:] This may like Firefox's password management system. Firefox stores master password and keys in key3.db file and use these values to access credentials stored in signons.sqlite file.
Firefox uses nsILoginManager interface for its operations.
回答1:
XPCOM doesn't currently provide a way to use the encryption capabilities of NSS. You can use js-ctypes to call NSS functions directly - not simple but doable. You can take a look at the WeaveCrypto.js module for an example implementation using symmetric keys. The DOMCrypt extension for example essentially bundles WeaveCrypto.js
with the extension and only calls its functions then (using the version distributed with the browser isn't recommendable - this is an internal module and its API could change any time).
来源:https://stackoverflow.com/questions/7753130/xpcom-encrypt-decrypt-operation-on-file-in-firefox-extension