Cryptography - atabegruslan/Notes GitHub Wiki
Hashing / Encoding / Encryption
https://www.youtube.com/watch?v=NuyzuNBFWxQ
Firstly, the above 3 are different things.
Hashes are 1-way functions. Some examples:
- MD5 (obsolete)
- SHA256
- argon2 (newest as of 2023)
- PBRDF2
- Bcrypt
- Scrypt
The returned hash is also called the digest. It is commonly in the hex
or base64
formats.
HMAC is a type of hashing algorithm that requires a password (ie: a symmetric key). The resulting hash is commonly in hex
format.
Encoding:
base64
is an example of encoding- https://github.com/atabegruslan/Notes/wiki/Encoding
Encryption is when the original text can be recovered if you have the key. Some examples:
- Symmetric
- DES
- RC4
- AES256. Result is commonly in
hex
format
- Assymetric
- Diffie Helmann
- DSA
- ECDSA
- ed25519
- PGP
- RSA. Its public key can have encode-type of
spki
& format ofpem
. Its private key can have encode-type ofpkcs8
& format ofpem
& cypher ofaes-256-cbc
& can have a passphrase.
Signing = First hashing the content, then encrypting it. Then appending it to the content.
Caesar code:
E is: go forward N letters in the alphabet, rotating from Z to A.
k is N
D is: go back N letters in the alphabet, rotating from A to Z.
k' is N
When k = k' we speak of a symmetric‐key algorithm or a shared key. Both ends must know the same secret key.
XOR
A symmetric cryptographic algorithm:
P=110011, k=010101 ‐> C=XOR(110011,010101)=100110 C=100110, k=010101 ‐> P=XOR(100110,010101)=110011
In this example there are 26 = 64 possible keys, so it's easy to find the key by trial and error.
1 - DES/3xDES
A block cipher.
If anyone encrypts the same cleartext under the same key k, they'll get the same ciphertext.
CBC
Cipher Block Chaining. A Quick‐and‐Dirty Stream Cipher.
Before each 64‐bit plaintext block Pn is encrypted, XOR it with the previous cyphertext block Cn‐1.
Repeated blocks are now very rare.
Should also compress cleartext before encrypting it.
2 - AES
128 bit block cipher with 128, 192 or 256 bit keys.
Mathematically complex.
Better software performance.
Involves transposition steps and XOR & also includes substitution tables in each round.
Diffie-Hellmann
Both sender and receiver produce the same symmetrical key without eavesdropper finding out.
Sender and Receiver share a pair of numbers,
then mix in their own unique private numbers with that pair of number,
they pass their results to each other.
Even if eavesdropper gets those 2 numbers, he won't figure out symmetrical key,
as the symmetrical key is generated by reversing the original pair of the starting numbers with either sender's or receiver's private number.
https://www.youtube.com/watch?v=YEBfamv-_do
3 - RSA
https://www.youtube.com/watch?v=Pq8gNbvfaoM
Assymmetrical key, based on number theory - mathematical process of generating a public key and another private key:
Choose two large prime numbers p and q
Let n = pq
Let n' = (p‐1)x(q‐1)
Find k which has no common factors with n'.
k will be the encryption (public) key.
Find k' such that (kk'‐1) is an exact multiple of n'.
k' will be the decryption (private) key.
Encryption consists of raising each block of the plaintext to the power k, modulo n.
Decryption consists of raising each block of the cyphertext to the power k', modulo n.
The sending computer encrypts the document with a symmetric key,
then encrypts the symmetric key with the public key of the receiving computer. The receiving computer uses its private key to decode the symmetric key.
It then uses the symmetric key to decode the document.
Large scale public key encryption: CA and digital certificate.
SHA & MD5 are hash algorithms.
Symmetric vs. Asymmetric Encryption
Both create secure channels, check message authenticity and build authentication protocols.
But only based on some prior knowledge (a public key) and on some trusted 3rd party.
https://github.com/atabegruslan/Notes/blob/main/notes/security/symmetric_assymmetric.pdf