crypto#pbkdf2Sync JavaScript Examples

The following examples show how to use crypto#pbkdf2Sync. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: nexoDerivedKeyGenerator.js    From Lynx with MIT License 6 votes vote down vote up
NexoDerivedKeyGenerator = /** @class */ (function () {
    function NexoDerivedKeyGenerator() {
    }
    NexoDerivedKeyGenerator.deriveKeyMaterial = function (passphrase) {
        var pass = Buffer.from(passphrase, "binary");
        var salt = Buffer.from("AdyenNexoV1Salt", "binary");
        var iterations = 4000;
        var keylen = NEXO_CIPHER_KEY_LENGTH + NEXO_HMAC_KEY_LENGTH + NEXO_IV_LENGTH;
        var key = pbkdf2Sync(pass, salt, iterations, keylen * 8, "sha1");
        return NexoDerivedKeyGenerator.readKeyData(key);
    };
    NexoDerivedKeyGenerator.readKeyData = function (key) {
        return {
            cipherKey: key.slice(NEXO_HMAC_KEY_LENGTH, NEXO_HMAC_KEY_LENGTH + NEXO_CIPHER_KEY_LENGTH),
            hmacKey: key.slice(0, NEXO_HMAC_KEY_LENGTH),
            iv: key.slice(NEXO_HMAC_KEY_LENGTH + NEXO_CIPHER_KEY_LENGTH, NEXO_CIPHER_KEY_LENGTH + NEXO_HMAC_KEY_LENGTH + NEXO_IV_LENGTH),
        };
    };
    return NexoDerivedKeyGenerator;
}())
Example #2
Source File: timing_attack_node.js    From njsscan with GNU Lesser General Public License v3.0 5 votes vote down vote up
create(password) {
        const salt = randomBytes(128).toString('base64'); // <- salt 
        // salt was not base64 before being used by pbkdf2

        const hash = pbkdf2Sync(password, salt, this.iters, this.keylen, this.digest).toString('base64');

        return [salt, hash, this.iters].join('::');
    }
Example #3
Source File: timing_attack_node.js    From njsscan with GNU Lesser General Public License v3.0 5 votes vote down vote up
verify(stored, password) {
        const [salt, hash, iters] = stored.split('::');
        const verify = pbkdf2Sync(password, salt, parseInt(iters, 10), this.keylen, this.digest);

        // ruleid:node_timing_attack
        return hash === verify.toString('base64');
    }