Hashing and Encryption — Security · NestJS

Stop storing passwords: hash them with bcrypt at registration and compare at sign-in. Then the other direction, for data that must be read back: encrypt each cat's microchip number with AES under a key derived with scrypt, a fresh IV per record.

What you will learn

Read the theory for Hashing and Encryption

All Security lessons

All NestJS courses

loading types…

What you'll learn

  • Tell hashing from encryption, and say which one a password gets and which one data you must read back gets
  • Hash a password with bcrypt at a chosen cost and check a sign-in with compare, never by comparing strings
  • Derive an encryption key from a password with scrypt and encrypt with aes-256-ctr under a fresh IV per message, storing the IV with the ciphertext
  • Read the shape of a bcrypt hash and of a stored ciphertext, and know what each gives away (nothing)