博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python 常用库(随时补充)
阅读量:4709 次
发布时间:2019-06-10

本文共 1097 字,大约阅读时间需要 3 分钟。

 

1. 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  resp. . 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!

转载于:https://www.cnblogs.com/tangkaixin/p/6756791.html

你可能感兴趣的文章
RTP Payload Format for Transport of MPEG-4 Elementary Streams over http
查看>>
Java环境变量设置
查看>>
【JBPM4】判断节点decision 方法3 handler
查看>>
filter 过滤器(监听)
查看>>
node启动时, listen EADDRINUSE 报错;
查看>>
杭电3466————DP之01背包(对状态转移方程的更新理解)
查看>>
python--注释
查看>>
SQL case when else
查看>>
SYS_CONTEXT 详细用法
查看>>
Pycharm配置autopep8让Python代码更符合pep8规范
查看>>
我的第一篇博客
查看>>
【C++算法与数据结构学习笔记------单链表实现多项式】
查看>>
C#垃圾回收机制
查看>>
31、任务三十一——表单联动
查看>>
python之hasattr、getattr和setattr函数
查看>>
maven使用阿里镜像配置文件
查看>>
Copy code from eclipse to word, save syntax.
查看>>
arguments.callee的作用及替换方案
查看>>
Centos 6.5下的OPENJDK卸载和SUN的JDK安装、环境变量配置
查看>>
【.Net基础03】HttpWebRequest模拟浏览器登陆
查看>>