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!
  • 相关阅读:
    学习第23天
    学习第22天
    学习第21天
    Servlet交互与JSP
    Cookie与Session
    servlet入门
    网络编程
    DOM4j
    xml文档对象模型doc
    反射
  • 原文地址:https://www.cnblogs.com/tangkaixin/p/6756791.html
Copyright © 2011-2022 走看看