本文整理汇总了TypeScript中crypto.pbkdf2Sync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript pbkdf2Sync函数的具体用法?TypeScript pbkdf2Sync怎么用?TypeScript pbkdf2Sync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pbkdf2Sync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: Error
return Promise.resolve().then(() => {
// must be bip39 mnemonic
if (!bip39.validateMnemonic(phrase)) {
throw new Error('Not a valid bip39 nmemonic')
}
// normalize plaintext to fixed length byte string
const plaintextNormalized = Buffer.from(
bip39.mnemonicToEntropy(phrase), 'hex'
)
// AES-128-CBC with SHA256 HMAC
const salt = crypto.randomBytes(16)
const keysAndIV = crypto.pbkdf2Sync(password, salt, 100000, 48, 'sha512')
const encKey = keysAndIV.slice(0, 16)
const macKey = keysAndIV.slice(16, 32)
const iv = keysAndIV.slice(32, 48)
const cipher = crypto.createCipheriv('aes-128-cbc', encKey, iv)
let cipherText = cipher.update(plaintextNormalized).toString('hex')
cipherText += cipher.final().toString('hex')
const hmacPayload = Buffer.concat([salt, Buffer.from(cipherText, 'hex')])
const hmac = crypto.createHmac('sha256', macKey)
hmac.write(hmacPayload)
const hmacDigest = hmac.digest()
const payload = Buffer.concat([salt, hmacDigest, Buffer.from(cipherText, 'hex')])
return payload
})
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:31,代码来源:wallet.ts
示例2: function
UserSchema.methods.hashPassword = function(password) {
if (this.salt && password) {
return crypto.pbkdf2Sync(password, this.salt, 10000, 64).toString("base64");
} else {
return password;
}
};
开发者ID:cm0s,项目名称:mea2n,代码行数:7,代码来源:user.model.ts
示例3: HashSync
export function HashSync(data: string, salt?: string)
{
if (typeof salt === 'undefined' || !salt)
{
salt = GenSalt();
}
const key = crypto.pbkdf2Sync(data, salt, 150000, HASHLENGHT, 'sha512').toString('hex');
return salt + key;
}
开发者ID:Kasperki,项目名称:NodeBlog,代码行数:11,代码来源:Hash.ts
示例4: makeHash
export function makeHash(decryptedPassword:string, salt?:string):hashResult {
if (!salt) {
salt = crypto.randomBytes(16).toString('base64')
}
const saltBuf = new Buffer(salt, 'base64')
const hashedPassword = crypto.pbkdf2Sync(`${LOCAL_AUTH_SALT}${decryptedPassword}`, saltBuf, 10000, 512, 'sha512')
return {
hashedPassword: hashedPassword.toString(),
salt: salt
}
}
开发者ID:memolog,项目名称:mean-edge,代码行数:11,代码来源:local.ts
示例5: encryptPassword
private encryptPassword(password: string, salt: string): string{
if (!password || !salt) {
return null;
}
let defaultIterations = 10000;
let defaultKeyLength = 64;
let base64Salt = new Buffer(salt, 'base64');
return crypto.pbkdf2Sync(password, base64Salt, defaultIterations, defaultKeyLength, 'sha512')
.toString('base64');
}
开发者ID:steelheaddigital,项目名称:angular2-express-starter,代码行数:12,代码来源:user_service.ts
示例6: hashPassword
export function hashPassword(plaintext: string, salt: string, options: IPasswordOptions): string {
assert.ok(salt.length === options.saltLength, 'incompatible salt length')
return crypto
.pbkdf2Sync(
plaintext,
salt + options.secret,
options.iterations,
options.hashedPasswordLength / 2,
options.algorithm,
)
.toString('hex')
}
开发者ID:patrickhulce,项目名称:klay,代码行数:13,代码来源:password.ts
示例7: PasswordError
return Promise.resolve().then(() => {
const salt = dataBuffer.slice(0, 16)
const hmacSig = dataBuffer.slice(16, 48) // 32 bytes
const cipherText = dataBuffer.slice(48)
const hmacPayload = Buffer.concat([salt, cipherText])
const keysAndIV = crypto.pbkdf2Sync(password, salt, 100000, 48, 'sha512')
const encKey = keysAndIV.slice(0, 16)
const macKey = keysAndIV.slice(16, 32)
const iv = keysAndIV.slice(32, 48)
const decipher = crypto.createDecipheriv('aes-128-cbc', encKey, iv)
let plaintext = decipher.update(cipherText).toString('hex')
plaintext += decipher.final().toString('hex')
const hmac = crypto.createHmac('sha256', macKey)
hmac.write(hmacPayload)
const hmacDigest = hmac.digest()
// hash both hmacSig and hmacDigest so string comparison time
// is uncorrelated to the ciphertext
const hmacSigHash = crypto.createHash('sha256')
.update(hmacSig)
.digest()
.toString('hex')
const hmacDigestHash = crypto.createHash('sha256')
.update(hmacDigest)
.digest()
.toString('hex')
if (hmacSigHash !== hmacDigestHash) {
// not authentic
throw new PasswordError('Wrong password (HMAC mismatch)')
}
const mnemonic = bip39.entropyToMnemonic(plaintext)
if (!bip39.validateMnemonic(mnemonic)) {
throw new PasswordError('Wrong password (invalid plaintext)')
}
return mnemonic
})
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:43,代码来源:wallet.ts
示例8:
export const grades = functions.pubsub.topic('grades').onPublish(event => {
const { chicagoId, record } = event.data.json;
const basis = [record['term'], record['course'], record['section']].join();
const key = crypto
.pbkdf2Sync(basis, chicagoId, 2000000, 20, 'sha512')
.toString('base64')
.replace(/=/g, '')
.replace(/\+/g, '-')
.replace(/\//g, '_');
return admin
.firestore()
.collection('institutions')
.doc('uchicago')
.collection('grades')
.doc(key)
.set({
course: record['course'],
section: record['section'],
term: record['term'],
gpa: record['gpa'],
tenure: record['tenure'],
});
});
开发者ID:kevmo314,项目名称:canigraduate.uchicago.edu,代码行数:23,代码来源:index.ts
示例9: encryptPassword
*/
encryptPassword(password, callback): any {
if (!password || !this.salt) {
if (!callback) {
return null;
} else {
return callback('Missing password or salt');
}
}
let defaultIterations = 10000;
let defaultKeyLength = 64;
let salt = new Buffer(this.salt, 'base64');
if (!callback) {
return crypto.pbkdf2Sync(password, salt, defaultIterations, defaultKeyLength, 'sha512')
.toString('base64');
}
return crypto.pbkdf2(password, salt, defaultIterations, defaultKeyLength, 'sha512', (err, key) => {
if (err) {
callback(err);
} else {
callback(null, key.toString('base64'));
}
});
}
}
});
export default User;
开发者ID:projectSHAI,项目名称:expressgular2,代码行数:31,代码来源:user.model.ts
示例10: function
encryptPassword: function (password) {
if (!password || !this.salt) { return ''; }
var salt = new Buffer(this.salt, 'base64');
return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
}
开发者ID:NovaeWorkshop,项目名称:Nova,代码行数:5,代码来源:user.model.ts
注:本文中的crypto.pbkdf2Sync函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论