069 hmac module

hmac module

  • hmac module: password encryption, you can add salt

    To prevent password knocked library, we can use python in another hmac module, it created internally and content key to encrypt and then we had some sort of deal.

    If you want to ensure that the final result hmac module consistent, must ensure that:

    1. Hmac.new within parentheses as specified initial key
    2. No matter how many times the update, check the contents together to accumulate the same content
    import hmac
    
    # 注意hmac模块只接受二进制数据的加密
    h1 = hmac.new(b'hash')
    h1.update(b'hello')
    h1.update(b'world')
    print(h1.hexdigest())
    
    # 905f549c5722b5850d602862c34a763e
    h2 = hmac.new(b'hash')
    h2.update(b'helloworld')
    print(h2.hexdigest())
    
    # 905f549c5722b5850d602862c34a763e
    h3 = hmac.new(b'hashhelloworld')
    print(h3.hexdigest())
    
    # a7e524ade8ac5f7f33f3a39a8f63fd25

Guess you like

Origin www.cnblogs.com/xichenHome/p/11366357.html
069