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

    Security and Cryptography in Python - Hash Functions(4)

    Why iterate over hash function and demonstrated by implementation in Python

    Code in Python:

    import hashlib
    import base64
    
    
    def guess_password(salt, iterations, entropy):
        alphabet = "abcdefghijklmnopqrstuvwxyz"
        for c1 in alphabet:
            for c2 in alphabet:
                password = str.encode(c1 + c2)
                value = base64.b64encode(hashlib.pbkdf2_hmac("sha512", password, salt, iterations, dklen=128))
                if value == entropy:
                    return password
        return "".encode()
    
    
    iterations = 45454
    salt = base64.b64decode("6VuJKkHVTdDelbNMPBxzw7INW2NkYlR/LoW40L7kVAI=".encode())
    validation = "SALTED-SHA512-PBKDF2"
    entropy = "15KqQ3c+ozUsKvgNZmwU0GNT+De1x/W+/MBkotAgPnMHJ90YDrgYrQRvY4YkCdBhNs+JkStX7EjnCNWAAW5xATANwPlKwBdyFyqrkqnRyxtb+ccd2S2aflf1CwaDOGXl7RKyToGdNjPNzK0gWSaoFX7eSe6Eugnhw51ioPP/OUg=".encode()
    
    password = "??".encode()
    
    password = guess_password(salt, iterations, entropy)
    print(password)
    value = base64.b64encode(hashlib.pbkdf2_hmac("sha512", password, salt, iterations, dklen=128))
    print(value)
    print(entropy)
    
    

    Running Result (The password is 'pw'):

    image-20210307101612265

    相信未来 - 该面对的绝不逃避,该执著的永不怨悔,该舍弃的不再留念,该珍惜的好好把握。
  • 相关阅读:
    开放API接口安全处理!
    ant笔记
    并发调试
    IDEA 设置(中文乱码、svn、热部署、ideolog 、Jrebel )
    win10家庭版升级专业版
    org.json package
    'root'@'localhost'不能登录问题
    javascript之DOM选择符
    javascript之DOM(四其他类型)
    javascript之DOM(三Element类型)
  • 原文地址:https://www.cnblogs.com/keepmoving1113/p/14493558.html
Copyright © 2011-2022 走看看