1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/pbkdf2/index.js

39 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2023-12-18 13:12:25 +08:00
var native = require('crypto')
2024-01-16 21:26:16 +08:00
var checkParameters = require('./lib/precondition')
var defaultEncoding = require('./lib/default-encoding')
var toBuffer = require('./lib/to-buffer')
2023-12-18 13:12:25 +08:00
function nativePBKDF2 (password, salt, iterations, keylen, digest, callback) {
2024-01-16 21:26:16 +08:00
checkParameters(iterations, keylen)
password = toBuffer(password, defaultEncoding, 'Password')
salt = toBuffer(salt, defaultEncoding, 'Salt')
2023-12-18 13:12:25 +08:00
if (typeof digest === 'function') {
callback = digest
digest = 'sha1'
}
if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2')
return native.pbkdf2(password, salt, iterations, keylen, digest, callback)
}
function nativePBKDF2Sync (password, salt, iterations, keylen, digest) {
2024-01-16 21:26:16 +08:00
checkParameters(iterations, keylen)
password = toBuffer(password, defaultEncoding, 'Password')
salt = toBuffer(salt, defaultEncoding, 'Salt')
2023-12-18 13:12:25 +08:00
digest = digest || 'sha1'
return native.pbkdf2Sync(password, salt, iterations, keylen, digest)
}
/* istanbul ignore next */
if (!native.pbkdf2Sync || native.pbkdf2Sync.toString().indexOf('keylen, digest') === -1) {
exports.pbkdf2Sync = require('./lib/sync')
exports.pbkdf2 = require('./lib/async')
// native
} else {
exports.pbkdf2Sync = nativePBKDF2Sync
exports.pbkdf2 = nativePBKDF2
}