zoukankan      html  css  js  c++  java
  • Security and Cryptography in Python

    Security and Cryptography in Python - Hash Functions(3)

    How password are Verified

    https://docs.python.org/3/library/hashlib.html

    https://en.wikipedia.org/wiki/PBKDF2

    import hashlib
    import base64
    
    iterations = 45454
    salt = base64.b64decode("6VuJKkHVTdDelbNMPBxzw7INW2NkYlR/LoW40L7kVAI=".encode())
    #SALTED-SHA512-PBKDF2
    
    password = "password".encode()
    
    value = hashlib.pbkdf2_hmac("sha512", password, salt, iterations, dklen=128)
    print(base64.b64encode(value))
    

    Running Result:

    image-20210302204214142

    Why use Salt - to avoid other body see that you use the same password with them.
    import hashlib
    import base64
    
    iterations = 45454
    salt = base64.b64decode("6VuJKkHVTdDelbNMPBxzw7INW2NkYlR/LoW40L7kVAI=".encode())
    validation = "SALTED-SHA512-PBKDF2"
    
    password = "password".encode()
    
    value = hashlib.pbkdf2_hmac("sha512", password, salt, iterations, dklen=128)
    entropy = base64.b64encode(value)
    print("Alice", validation, salt, iterations, entropy)
    
    salt = "666".encode()
    password = "password".encode()
    value = hashlib.pbkdf2_hmac("sha512", password, salt, iterations, dklen=128)
    entropy = base64.b64encode(value)
    print("Bob", validation, salt, iterations, entropy)
    

    Running result:

    image-20210302210043656

    相信未来 - 该面对的绝不逃避,该执著的永不怨悔,该舍弃的不再留念,该珍惜的好好把握。
  • 相关阅读:
    U-Boot新手入门
    安装交叉编译工具
    Makefile 工程管理
    gcc基本用法
    poj 3264 Balanced Lineup
    hdoj 1166 敌兵布阵
    poj 1363 Rails
    poj 1028 Web Navigation
    zoj 3621 Factorial Problem in Base K
    poj1861最小生成树
  • 原文地址:https://www.cnblogs.com/keepmoving1113/p/14471154.html
Copyright © 2011-2022 走看看