How to use the pkcs5 function from node-forge
Find comprehensive JavaScript node-forge.pkcs5 code examples handpicked from public code repositorys.
GitHub: mitro-co/keyczarjs
![mitro-co profile picture](/mitro-co.png?size=40)
207 208 209 210 211 212 213 214 215 216
function _deriveKey(password, salt, iterationCount) { // check ! > 0 so that it fails for undefined if (!(iterationCount > 0)) { throw new Error('Invalid iterationCount: ' + iterationCount); } return forge.pkcs5.pbkdf2( password, salt, iterationCount, _PBE_AES_KEY_BYTES, forge.md.sha1.create()); } var PBE_DECRYPT_FAILED_MESSAGE = 'AES decryption failed (password incorrect or data is corrupt?)';
+ 3 other calls in file
GitHub: Andy0570/evernote
![Andy0570 profile picture](/Andy0570.png?size=40)
343 344 345 346 347 348 349 350 351 352
// 生成基于口令的 16 进制密钥 // note an optional message digest can be passed as the final parameter // 注意,可以将可选的消息摘要算法作为最终参数传递 var salt = forge.random.getBytesSync(128); var derivedKey = forge.pkcs5.pbkdf2('password', salt, numIterations, 16); // 异步生成密钥 // note an optional message digest can be passed before the callback forge.pkcs5.pbkdf2('password', salt, numIterations, 16, function(err, derivedKey) {
207 208 209 210 211 212 213 214 215 216 217 218
} function generateTeamKey() { const salt = forge.random.getBytesSync(16); const randomKey = forge.random.getBytesSync(32); const teamKey = forge.pkcs5.pbkdf2(randomKey, salt, 10000, 32); return teamKey; }
+ 3 other calls in file
186 187 188 189 190 191 192 193 194 195 196
} export function setupNewItemKey() { const salt = forge.random.getBytesSync(16); const randomKey = forge.random.getBytesSync(32); const itemKey = forge.pkcs5.pbkdf2(randomKey, salt, 10000, 32); return itemKey; } export async function createANewItem(titleStr, currentContainer, selectedItemType, addAction, targetItem, targetPosition, workspaceKey, searchKey, searchIV) {
GitHub: VladPryad/wallet-cipher
30 31 32 33 34 35 36 37 38 39 40 41
// console.debug("PK from seed: ", accFromSeed.getPublicKey(0)); // console.debug("SK from seed: ", accFromSeed.getSecret(0)); function formatPass(pass) { const keySize = 16; const key = forge.pkcs5.pbkdf2(pass, eightBytes, 1000, keySize); return key; } function validateMnemonic(mnemonic) {
3 4 5 6 7 8 9 10 11 12 13
const validateKeyMiddleware = async (req, res, next) => { const {inputKey, username} = req.body; async function validateKey(inputKey, username){ var iv = await getIV(username); var key = forge.pkcs5.pbkdf2(inputKey, iv, 1, 16); try { let doc = await query(username, key); res.json({status: 'ok'}); return key;
+ 3 other calls in file
185 186 187 188 189 190 191 192 193 194
users.findOne({username: username}) .then(user => { if(user === null){ callback(null, false) }else{ const passwordEncrypted = forge.pkcs5.pbkdf2( password, // Plain text password user.salt, // Salt stored in database 1, // Iteration number 32, // 32 bytes length
+ 3 other calls in file
247 248 249 250 251 252 253 254 255 256
const salt = pbkdf2Seq[0].value; const iterations = pbkdf2Seq[1].value.charCodeAt(); // Prepending 0x040e, where 0x04 = octetstring, 0x0e = string length (14) const iv = '' + decodedItemSeq[0].value[1].value[1].value[1].value; const k = sha1(globalSalt + password); const key = forge.pkcs5.pbkdf2(k, salt, iterations, 32, forge.md.sha256.create()); return decrypt(data, iv, key, 'AES-CBC'); } function decrypt(data, iv, key, algorithm) {
194 195 196 197 198 199 200 201 202 203 204 205
export function generateLocalVaultKey(password) { const numIterations = 5000; let localVaultSalt = forge.random.getBytesSync(128); let localVaultIV = forge.random.getBytesSync(12); let localVaultKey = forge.pkcs5.pbkdf2(password, localVaultSalt, numIterations, 16); return [ localVaultSalt, localVaultIV, localVaultKey ]; } export function getLocalVaultKey(salt, password) {
node-forge.pki is the most popular function in node-forge (10287 examples)