An encoding technique, in which message (text, json…) is encoded by encryption algorithm that only authorized people can read the message.
RSA (Private key, public key)
if hacker can retrieve the database, they can extract password of users and use them for different sites
engineer and Database admin can access the password
Encrypted/Encode passwords (reversible)
Encrypt password by an encryption algorithm. (base64, rsa, …)
Hacker can register and know his password and the encrypted form => guess the encryption logic => decrypt all other passwords
Hash password (not reversible)
Use hash function to hash the password before storing:
hash function is irreversible: choose the secure hash functions: SHA256, SHA512
avoid MD5, SHA1:
high chance of collisions (2 diff keys => same value)
big dictionary (21232f297a57a5a743894a0e4a801fc3)
risks:
Select a password you think the victim has chosen (e.g.password1!, 123456, qwerty)
Calculate the hash
Compare the hash you calculated to the hash of the victim. If they match, you have correctly “cracked” the hash
and now know the plaintext value of their password.
Hash + Salt
A salt is a unique, randomly generated string that is added to each password as part of the hashing process
Salt is stored in database.
Purpose:
hacker has to crack hashes one at a time instead of calculating the hash once and compare with every stored hash. => slow hacking process
impossible to check if 2 users have same password. hashed_password = hash(unique_salt + password)
Hash + Salt + Pepper
Pepper is a randomly generated string that is added to password as part of the hashing process.
Similar to Salt, but:
pepper is not stored in database. (env variable, secure centralized store)
pepper is shared between all passwords rather than being unique like a salt.
Purpose:
prevent hacker from cracking any hash if they only have access to the database.
Slow Hash + Salt + Pepper
SHA-X hash is fast to compute => with a strong computer, hacker can brute force
Use Slow Hash: bcrypt, scrypt
they “slow down” its hashing speed => take very long time to brute force.
SSL => deprecated => now use TLS. a cryptographic protocol designed to provide communications security over a computer network.
Part of HTTPS protocol
Before client and server can send and receive data securely using HTTPS, they need to do TLS handshake to verify each other and exchange necessary information.
Json Web Token: an open standard that defines a way for securely transmitting data between parties (client, server).
This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret or
a public/private key pair using RSA.
example
Usage: Authentication
Advantage:
stateless: server does not need to maintain a session storage because all authentication information is stored
in JWT, which is stored in client side (browser).
because JWT is sent along with the request in the request header, it eliminates the possibility of CSRF (Cross-site
Request Forgery) attack.
Disadvantage:
JWT only becomes invalid when it expires. The user has no built-in feature to revoke the validity of a token explicitly
The solution would be to create a database to maintain a revocation list. This would add complexity to the system and eliminate the stateless property of JWT authentication.
“A web application using APIs can only request HTTP resources from the same origin the application was loaded from.”
a policy that is compiled by most of the browsers (for security reason)