-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathq.js
32 lines (28 loc) · 1.05 KB
/
q.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* Node.js Crypt(3) Library -- Async version */
var createSalt = require('./createsalt.js');
var crypt3async = require('./async.js');
var _Q = require('q');
/** Crypt(3) password and data encryption.
* @param {string} key user's typed password
* @param {string} salt Optional salt, for example SHA-512 use "$6$salt$". Please note: SHA-512 only works on glibc2 systems.
* @param {function} callback The callback function, for example `function(err, hash)` where `hash` is {string} A generated hash in format `$id$salt$encrypted`
* @see https://en.wikipedia.org/wiki/Crypt_(C)
*/
var crypt3 = module.exports = function(key, salt) {
salt = salt || createSalt();
var defer = _Q.defer();
crypt3async(key, salt, function(err, value) {
if(err) {
defer.reject(err);
} else {
defer.resolve(value);
}
});
return defer.promise;
};
/** Create salt
* @param {string} type The type of salt: md5, blowfish (only some linux distros), sha256 or sha512. Default is sha512.
* @returns {string} Generated salt string
*/
crypt3.createSalt = createSalt;
/* EOF */