How to use the browserify-cipher.createDecipheriv function in browserify-cipher

To help you get started, we’ve selected a few browserify-cipher examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elevenyellow / coinfy / web / src / util / aes.js View on Github external
window.go = function(){

var password='holamundo'
var enc=toV3('If the text is very very long?', password)
console.log( enc );

var ciphertext = new Buffer(enc.ciphertext, 'hex')
var derivedKey = scrypt(new Buffer(password), new Buffer(enc.kdfparams.salt, 'hex'), enc.kdfparams.n, enc.kdfparams.r, enc.kdfparams.p, enc.kdfparams.dklen)
var decipher = createDecipheriv(enc.cipher, derivedKey.slice(0, 16), new Buffer(enc.cipherparams.iv, 'hex'))
var seed = decipherBuffer(decipher, ciphertext, 'hex')
console.log( 'DECRYPTED yeah!', seed.toString() );

}
github ethereum / web3.js / packages / web3-eth-accounts / src / models / Account.js View on Github external
kdfparams.c,
                kdfparams.dklen,
                'sha256'
            );
        } else {
            throw new Error('Unsupported key derivation scheme');
        }

        const ciphertext = Buffer.from(json.crypto.ciphertext, 'hex');

        const mac = keccak256(Buffer.concat([derivedKey.slice(16, 32), ciphertext])).replace('0x', '');
        if (mac !== json.crypto.mac) {
            throw new Error('Key derivation failed - possibly wrong password');
        }

        const decipher = createDecipheriv(
            json.crypto.cipher,
            derivedKey.slice(0, 16),
            Buffer.from(json.crypto.cipherparams.iv, 'hex')
        );
        const seed = `0x${Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString('hex')}`;

        return Account.fromPrivateKey(seed, accounts);
    }
}
github ethereum / web3.js / src / wallet / accounts / EthereumAccount.js View on Github external
kdfparams.c,
                kdfparams.dklen,
                'sha256'
            );
        } else {
            throw new Error('Unsupported key derivation scheme');
        }

        const ciphertext = Buffer.from(json.crypto.ciphertext, 'hex');

        const mac = keccak256(Buffer.concat([derivedKey.slice(16, 32), ciphertext])).replace('0x', '');
        if (mac !== json.crypto.mac) {
            throw new Error('Key derivation failed - possibly wrong password');
        }

        const decipher = createDecipheriv(
            json.crypto.cipher,
            derivedKey.slice(0, 16),
            Buffer.from(json.crypto.cipherparams.iv, 'hex')
        );
        const seed = `0x${Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString('hex')}`;

        return Account.fromPrivateKey(seed, accounts);
    }
}
github elevenyellow / coinfy / src / api / security.js View on Github external
export function decryptAES128CTR(encryption, password, hex=false) {
    const ciphertype = 'aes-128-ctr'
    const ciphertext = new Buffer(encryption.ciphertext, 'hex')
    const derivedKey = encryption.kdf==='scrypt' ?
        scrypt(new Buffer(password), new Buffer(encryption.kdfparams.salt, 'hex'), encryption.kdfparams.n, encryption.kdfparams.r, encryption.kdfparams.p, encryption.kdfparams.dklen)
    :
        pbkdf2.pbkdf2Sync(new Buffer(password), new Buffer(encryption.kdfparams.salt, 'hex'), encryption.kdfparams.c, encryption.kdfparams.dklen, 'sha256')
    const decipher = createDecipheriv(ciphertype, derivedKey.slice(0, 16), new Buffer(encryption.cipherparams.iv, 'hex'))
    let seed = Buffer.concat([decipher.update(ciphertext), decipher.final()])
    while (seed.length < 32)
        seed = Buffer.concat([new Buffer([0x00]), seed]);

    return seed.toString(hex?'hex':undefined) //ethereum seed.toString('hex')
}