zoukankan      html  css  js  c++  java
  • Python 常用库(随时补充)

     

    1. Python-RSA使用手册

    英文文档见Python-RSA使用手册,主要介绍了Python-RSA的消息的加密解密、文件的加密解密以及签名的方法。

    Installation

    使用pip install rsa安装Python-RSA模块

    Generating keys

    >>> import rsa
    >>> (pubkey, privkey) = rsa.newkeys(512)

    Encryption and decryption

    To encrypt or decrypt a message, use rsa.encrypt() resp. rsa.decrypt(). Let’s say that Alice wants to send a message that only Bob can read.

    1. Bob generates a keypair, and gives the public key to Alice. This is done such that Alice knows for sure that the key is really Bob’s (for example by handing over a USB stick that contains the key).

      >>> import rsa
      >>> (bob_pub, bob_priv) = rsa.newkeys(512)
    2. Alice writes a message, and encodes it in UTF-8. The RSA module only operates on bytes, and not on strings, so this step is necessary.

      >>> message = 'hello Bob!'.encode('utf8')
    3. Alice encrypts the message using Bob’s public key, and sends the encrypted message.

      >>> import rsa
      >>> crypto = rsa.encrypt(message, bob_pub)
    4. Bob receives the message, and decrypts it with his private key.

      >>> message = rsa.decrypt(crypto, bob_priv)
      >>> print(message.decode('utf8'))
      hello Bob!
  • 相关阅读:
    DC中为什么要用Uniquify?
    hdu 1596 find the safest road
    hdu2112 HDU Today
    hdu 2066 一个人的旅行
    poj 3026 Borg Maze
    poj 1979 Red and Black
    poj 1321 棋盘问题
    hdu 1010 Tempter of the Bone
    hdu 4861 Couple doubi
    codeforces584B Kolya and Tanya
  • 原文地址:https://www.cnblogs.com/tangkaixin/p/6756791.html
Copyright © 2011-2022 走看看