-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcreatesalt.js
More file actions
24 lines (19 loc) · 858 Bytes
/
createsalt.js
File metadata and controls
24 lines (19 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/** Node.js Crypt(3) Library */
var salters = {
'md5': function() { return '$1$'+require('crypto').randomBytes(10).toString('base64'); },
'blowfish': function() { return '$2a$'+require('crypto').randomBytes(10).toString('base64'); },
'sha256': function() { return '$5$'+require('crypto').randomBytes(10).toString('base64'); },
'sha512': function() { return '$6$'+require('crypto').randomBytes(10).toString('base64'); }
};
function createSalt(type) {
type = type || 'sha512';
if(!salters[type]) throw new TypeError('Unknown salt type at crypt3.createSalt: ' + type);
return salters[type]();
};
createSalt.salters = salters;
/** 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
*/
module.exports = createSalt;
/* EOF */