jackie / Andrea Ida Malkah Klaura <jackie@diebin.at>
12th March 2019
CodeFactory
is a hash function that
M % K = H
e.g.:
23 % 5 = 3 42523 % 5 = 3 42 % 5 = 2 23542 % 5 = 2
Some examples:
Remember: MD5 and SHA-1 are already broken
Using key-derivation functions
pbkdf2
Let's install:
$ pip3 install pbkdf2
#!/usr/bin/python3
from pbkdf2 import PBKDF2
import os
import base64
passphrase = "This is my aweseomest most annoyingly long passphrase with no extra security features whatsoever!"
salt = os.urandom(8)
derivedKey = PBKDF2(passphrase, salt).read(32)
print("The derived key is:")
print(base64.b64encode(derivedKey))
#!/usr/bin/python3
from pbkdf2 import PBKDF2
from Crypto.Cipher import AES
from Crypto import Random
import base64
passphrase = "This is my aweseomest most annoyingly long passphrase with no extra security features whatsoever!"
salt = Random.new().read(8)
derivedKey = PBKDF2(passphrase, salt).read(32)
initialisationVector = Random.new().read(16)
cipher = AES.new(derivedKey, AES.MODE_CBC, initialisationVector)
# Now lets encipher something
encryptedMessage = base64.b64encode(cipher.encrypt("Hey there! It's nothing important, still secret!"))
print("The encrypted message is:")
print(encryptedMessage)
#!/usr/bin/python3
from pbkdf2 import crypt
passphrase = "This is my aweseomest most annoyingly long passphrase with no extra security features whatsoever!"
otherPass = "ladida_so_funny"
print("The crypted passphrase:")
print(crypt(passphrase))
print("The crypted other passphrase (with default 400 iterations):")
print(crypt(otherPass))
print("The crypted other passphrase, but with 500 iterations")
print(crypt(otherPass, iterations=500))
print("The crypted other passphrase, but with 1024 iterations")
print(crypt(otherPass, iterations=1024))
print("The crypted other passphrase, but with 4096 iterations")
print(crypt(otherPass, iterations=4096))
Some guidlines:
These slides:
https://tantemalkah.at/2019/fempy_hashing
E-Mail:
jackie@diebin.at