Python Crypto.Cipher加密包

The Crypto.Cipher package contains algorithms for protecting the confidentiality of data.

Crypto.Cipher包含保护机密数据的加密算法。

Installation(安装)

  1. an almost drop-in replacement for the old PyCrypto library. You install it with:
    替换旧版本PyCrypto库安装

    pip install pycryptodome
    
  2. a library independent of the old PyCrypto. You install it with:
    独立于旧版本PyCrypto库的安装

    pip install pycryptodomex
    

Introduction(介绍)

There are three types of encryption algorithms:
Crypto.Cipher包含三种加密算法

  • Symmetric ciphers: all parties use the same key, for both decrypting and encrypting data. Symmetric ciphers are typically very fast and can process very large amount of data.
    对称加密算法:加解密数据使用同一秘钥,对称加密算法速度极快,能够快速处理非常庞大的数据。

  • Asymmetric ciphers: senders and receivers use different keys. Senders encrypt with public keys (non-secret) whereas receivers decrypt with private keys (secret). Asymmetric ciphers are typically very slow and can process only very small payloads. Example: PKCS#1 OAEP (RSA).
    非对称加密算法:发送者与接收者使用不同的秘钥,发送者使用公钥(非密)加密而接收者使用私钥解密。非对称加密算法速度很慢,只能够处理非常少的有效载荷(数据)。例如PKCS#1 OAEP (RSA)。

  • Hybrid ciphers: the two types of ciphers above can be combined in a construction that inherits the benefits of both. An asymmetric cipher is used to protect a short-lived symmetric key, and a symmetric cipher (under that key) encrypts the actual message.
    混合型加密算法:结合以上两种加密算法的优势。非对称加密算法经常被用来保护短活的对称秘钥,对称加密算法(使用对称秘钥)加密真实的信息。

基本的cipher API

You instantiate a cipher object by calling the new() function from the relevant cipher module (e.g. Crypto.Cipher.AES.new()). The first parameter is always the cryptographic key; its length depends on the particular cipher. You can (and sometimes must) pass additional cipher- or mode-specific parameters to new() (such as a nonce or a mode of operation).

通过从相关的cipher模块中调用new()函数实例化一个cipher对象(e.g. Crypto.Cipher.AES.new()),第一个参数是秘钥,长度
  • 6
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值