5

These modules are required like that

const crypto = require('crypto');
const bcrypt = require('bcrypt');

I'm very confused in between them. I want to know what is difference between them and when it should be used.

1
  • Removed the line asking for an example as that is explicitly off topic on this Q/A site. Apr 12, 2017 at 23:15

1 Answer 1

8

The bcrypt module contains an implementation of the bcrypt password hashing algorithm and nothing else.

The built-in crypto module contains many cryptographic primitives such as hashing, symmetric and asymmetric encryption, key exchange and some more. It doesn't contain an implementation of bcrypt, but there is an implementation of PBKDF2 which has a similar goal (password hashing) but not as good as bcrypt.

7
  • Hi, so if i am developing a banking app should i use bcrypt or crypto to encrypt the user information?
    – kd12345
    Mar 4, 2021 at 7:03
  • No idea. I haven't looked at the requirements of PCI DSS. You could use both. Whether you must is another question.
    – Artjom B.
    Mar 4, 2021 at 7:28
  • Should i use the builtin crypto module in node or crypto-js? Also, do you suggest i use scrypt or bcrypt?
    – kd12345
    Mar 4, 2021 at 7:37
  • 1. The crypto module probably uses optimized code in V8 whereas crypto-js is implemented purely in JS. If you don't care about performance then whatever you're more comfortable with. crypto-js only provides symmetric primitives whereas crypto provides asymmetric too. 2. scrypt with a high work factor which depends on the delay your users will tolerate.
    – Artjom B.
    Mar 5, 2021 at 18:07
  • Thank you for getting back to me. So, if i was to develop a banking app will bcrypt do the job in hashing the passwords or do you suggest i use the crypto module and encode using SHA?
    – kd12345
    Mar 6, 2021 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.