美文网首页
PyCrypto part 1: AES

PyCrypto part 1: AES

作者: cutelittlePanda | 来源:发表于2017-09-06 20:06 被阅读0次

    from Crypto.Cipher import AES

    encryptor = AES.new(key, AES_MODE, IV)

    * AES, advanced Encryption Standard, it is very fast and secure, it's the 'de facto' (in effect/in fact) standard of symmetric encription; it has a fixed block size of 16 bytes, its keys can be 128, 192, or 256 bits long.

    * key, a byte string, the secret key to use in the symmetric cipher, it must be 16(AES-128),24(AES-192), or 32(AES-256) bytes long.

    * MODE_constant: the chaining mode to use for encryption or decryption.

    AED.MODE_s: 

    MODE_CBC =2:

                                 Cipher-Block Chainning. 

    MODE_CFB = 3:

                            Cipher FeedBack

    MODE_ECB = 1:

                               Electronic Code Book

    MODE_OFB = 5:

                               Output FeedBack

    MODE_OPENPGP = 7.

    IV:  the initialization Vector to use for encryption or decryption, it's a byte string.

    1. it's ignored for MODE_ECB and MODE_CTR.

    2. it's mandatory for MODE_OPENPGP

    3. for other modes, it must be block_size long, and if it not present, then a given default value of all are zeros are used.

    As an example, encryption can be done as follows:

    from Crypto.Cipher import AES

    from Crypto import Random

    >>>key = b'Sixteen byte key'

    >>>iv = Random.new().read(AES.block_size)

    >>>cipher = AES.new(key, AES.MODE_CFB, iv)

    >>>msg = iv + cipher.encrypt(b'Attack at dawn')

    Doc Link: Crypto.Cipher.AES-module

    相关文章

      网友评论

          本文标题:PyCrypto part 1: AES

          本文链接:https://www.haomeiwen.com/subject/pkthcxtx.html