Tag: libsodium

如何为React Native修补/填充crypto.getRandomValues

我使用ReactNativify将一些为NodeJS创build的包移植到React Native,以将Node API对象依赖项重写为他们的browserify等价物。 其中之一是crypto 。 在transformer.js (或.babelrc )中我有: // The following plugin will rewrite imports. Reimplementations of node // libraries such as `assert`, `buffer`, etc. will be picked up // automatically by the React Native packager. All other built-in node // libraries get rewritten to their browserify counterpart. [require('babel-plugin-rewrite-require'), { aliases: { crypto: 'crypto-browserify', // […]

我对密码散列有什么误解?

这是我的理解,一个哈希函数将始终返回相同的结果时,提供相同的数据。 但是我一直在使用libsodium(通过节点钠),这不是发生了什么事情。 我在我的模式中有这个: UserSchema.pre('save', function(next) { // declare my variables let user = this, buf = Buffer.alloc(sodium.crypto_pwhash_STRBYTES, 'ascii'), passwordBuf = Buffer.from(user.password, 'ascii'), saltedPassBuf, hash; // only hash the password if it has been modified (or is new) if (!user.isModified('password')) return next(); // generate a salt sodium.randombytes_buf(buf, sodium.crypto_pwhash_STRBYTES, 'ascii'); // add salt to the password saltedPassBuf […]

在Node中使用libsodium.crypto_pwhash(Argon2)

我无法获得crypto_pwhash_str在我的Node项目中工作。 我正确导入了libsodium-wrappers-sumo和libsodium-sumo库,并能成功调用其他函数。 我对有问题的函数的调用如下所示: sodium.crypto_pwhash_str(password, 3, 4096, 'text') 在这种情况下,密码只是字母“a”的string对象。 当我运行debugging器,并试图找出发生了什么问题,我得到这个内部的代码块: if ((libsodium._crypto_pwhash_str(hashed_password_address, password_address, password_length, 0, opsLimit, 0, memLimit) | 0) === 0) { var ret = libsodium.Pointer_stringify(hashed_password_address); _free_all(address_pool); return ret; } _free_and_throw_error(address_pool); 它无法进入for循环,由于某种原因,对_crypto_pwhash_str()的调用的计算结果为-1 。 有没有人有任何与这个图书馆的经验,或可以帮助我弄清楚我做错了什么。 节点相当新,所以我很迷茫。

我正确地哈希密码?

我目前的项目是我的第一个Node.js(如果重要的话也使用MongoDB,Mongoose和Express),并且容易分心,我决定如何处理用户authentication的时候,已经落在了encryption的兔子洞里。 (这个项目不需要其他encryption)。 遵循这个页面上的模式(pattern,不是代码 – 我在安装node.bcrypt时遇到了问题,但是没有与node-Na一起使用), 而且这个页面我的过程是 新用户通过https提交密码 该模式会生成一个盐 模式散列密码和salt的串联 schema将盐和密码与用户信息一起存储 现在我不知道这是我个人的缺陷,但是我在遵循libsodium文档的时候遇到了麻烦。 节点钠不提供散列的任何附加信息(虽然它有一个encryption的例子)。 这是我想用来生成哈希的代码: let buf = new Buffer(sodium.crypto_pwhash_STRBYTES); sodium.randombytes_buf(buf, sodium.crypto_pwhash_STRBYTES); let salt = buf.toString(); let preBuffer = "somePass" + salt; let passwordBuf = Buffer.from(preBuffer); let hash = sodium.crypto_pwhash_str(passwordBuf, sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE); 所以问题是两个部分。 这是一个好的过程,是适当的代码?