zoukankan      html  css  js  c++  java
  • python--cryptography加密

    安装:pip install cryptography -i https://pypi.douban.com/simple  

    from cryptography.fernet import Fernet
    
    cipher_key = Fernet.generate_key()  #返回一个随机秘钥,每次是不同的
    #b'zM2vq7ekZ4Qse-B9NzzgyZHte8zlc-J0p4ack4gJ7is='
    cipher = Fernet(b'zM2vq7ekZ4Qse-B9NzzgyZHte8zlc-J0p4ack4gJ7is=')  #利用秘钥生成一个密码对象
    #<cryptography.fernet.Fernet object at 0x0000000002523948>
    
    text = b'My Is LiMing'  #需要加密的文本
    encrypted_text = cipher.encrypt(text)  #利用密码对象对文本加密
    #b'gAAAAABeFruWUqqsCtyeTLaeIkqbDHwtkjlm_V5vqrybPx0IanF4vjjfA2BnBoUY_M29E0Nvz0pY040WJ-hr_yhiHB0GVkrQKw=='
    decrypted_text = cipher.decrypt(encrypted_text)  #利用密码对象解密
    #b'My Is LiMing'
    
    print(cipher_key,cipher)
    print(encrypted_text)
    print(decrypted_text)

    我的问题:每次产生的秘钥是不一样的,以后怎么解密? 

  • 相关阅读:
    git中文输入显示问题
    how to write a DLL/SO in C/C++ for Python
    python,ctypes
    vc++,dll,lib文件百科
    c++ singleton
    build python on windows
    web前端后端
    动态链接库*.so的编译与使用
    qt,ui,QUiLoader
    qt,script
  • 原文地址:https://www.cnblogs.com/liming19680104/p/12169415.html
Copyright © 2011-2022 走看看