当前位置: 首页>>代码示例>>Python>>正文


Python aes.AES类代码示例

本文整理汇总了Python中pycryptopp.cipher.aes.AES的典型用法代码示例。如果您正苦于以下问题:Python AES类的具体用法?Python AES怎么用?Python AES使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AES类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _decrypt_rwcapdata

 def _decrypt_rwcapdata(self, encwrcap):
     salt = encwrcap[:16]
     crypttext = encwrcap[16:-32]
     key = hashutil.mutable_rwcap_key_hash(salt, self._node.get_writekey())
     cryptor = AES(key)
     plaintext = cryptor.process(crypttext)
     return plaintext
开发者ID:ArtRichards,项目名称:tahoe-lafs,代码行数:7,代码来源:dirnode.py

示例2: _crypt

 def _crypt(self, offset, data):
     offset_big = offset // 16
     offset_small = offset % 16
     iv = binascii.unhexlify("%032x" % offset_big)
     cipher = AES(self.key, iv=iv)
     cipher.process("\x00"*offset_small)
     return cipher.process(data)
开发者ID:tahoe-lafs,项目名称:tahoe-lafs,代码行数:7,代码来源:fileutil.py

示例3: _decrypt

 def _decrypt(self, crypttext, IV, readkey):
     self._status.set_status("decrypting")
     started = time.time()
     key = hashutil.ssk_readkey_data_hash(IV, readkey)
     decryptor = AES(key)
     plaintext = decryptor.process(crypttext)
     self._status.timings["decrypt"] = time.time() - started
     return plaintext
开发者ID:p-static,项目名称:tahoe-lafs,代码行数:8,代码来源:retrieve.py

示例4: _encrypt_rw_uri

def _encrypt_rw_uri(writekey, rw_uri):
    precondition(isinstance(rw_uri, str), rw_uri)
    precondition(isinstance(writekey, str), writekey)

    salt = hashutil.mutable_rwcap_salt_hash(rw_uri)
    key = hashutil.mutable_rwcap_key_hash(salt, writekey)
    cryptor = AES(key)
    crypttext = cryptor.process(rw_uri)
    mac = hashutil.hmac(key, salt + crypttext)
    assert len(mac) == 32
    return salt + crypttext + mac
开发者ID:ArtRichards,项目名称:tahoe-lafs,代码行数:11,代码来源:dirnode.py

示例5: test_previous_upload_failed

    def test_previous_upload_failed(self):
        self.basedir = "helper/AssistedUpload/test_previous_upload_failed"
        self.setUpHelper(self.basedir)

        # we want to make sure that an upload which fails (leaving the
        # ciphertext in the CHK_encoding/ directory) does not prevent a later
        # attempt to upload that file from working. We simulate this by
        # populating the directory manually. The hardest part is guessing the
        # storage index.

        k = FakeClient.DEFAULT_ENCODING_PARAMETERS["k"]
        n = FakeClient.DEFAULT_ENCODING_PARAMETERS["n"]
        max_segsize = FakeClient.DEFAULT_ENCODING_PARAMETERS["max_segment_size"]
        segsize = min(max_segsize, len(DATA))
        # this must be a multiple of 'required_shares'==k
        segsize = mathutil.next_multiple(segsize, k)

        key = hashutil.convergence_hash(k, n, segsize, DATA, "test convergence string")
        assert len(key) == 16
        encryptor = AES(key)
        SI = hashutil.storage_index_hash(key)
        SI_s = si_b2a(SI)
        encfile = os.path.join(self.basedir, "CHK_encoding", SI_s)
        f = open(encfile, "wb")
        f.write(encryptor.process(DATA))
        f.close()

        u = upload.Uploader(self.helper_furl)
        u.setServiceParent(self.s)

        d = wait_a_few_turns()

        def _ready(res):
            assert u._helper
            return upload_data(u, DATA, convergence="test convergence string")

        d.addCallback(_ready)

        def _uploaded(results):
            the_uri = results.get_uri()
            assert "CHK" in the_uri

        d.addCallback(_uploaded)

        def _check_empty(res):
            files = os.listdir(os.path.join(self.basedir, "CHK_encoding"))
            self.failUnlessEqual(files, [])
            files = os.listdir(os.path.join(self.basedir, "CHK_incoming"))
            self.failUnlessEqual(files, [])

        d.addCallback(_check_empty)

        return d
开发者ID:zooko,项目名称:tahoe-lafs,代码行数:53,代码来源:test_helper.py

示例6: _decrypt_segment

 def _decrypt_segment(self, segment_and_salt):
     """
     I take a single segment and its salt, and decrypt it. I return
     the plaintext of the segment that is in my argument.
     """
     segment, salt = segment_and_salt
     self._set_current_status("decrypting")
     self.log("decrypting segment %d" % self._current_segment)
     started = time.time()
     key = hashutil.ssk_readkey_data_hash(salt, self._node.get_readkey())
     decryptor = AES(key)
     plaintext = decryptor.process(segment)
     self._status.accumulate_decrypt_time(time.time() - started)
     return plaintext
开发者ID:jsgf,项目名称:tahoe-lafs,代码行数:14,代码来源:retrieve.py

示例7: CiphertextDownloader

class DecryptingConsumer:
    """I sit between a CiphertextDownloader (which acts as a Producer) and
    the real Consumer, decrypting everything that passes by. The real
    Consumer sees the real Producer, but the Producer sees us instead of the
    real consumer."""
    implements(IConsumer, IDownloadStatusHandlingConsumer)

    def __init__(self, consumer, readkey, offset):
        self._consumer = consumer
        self._read_ev = None
        self._download_status = None
        # TODO: pycryptopp CTR-mode needs random-access operations: I want
        # either a=AES(readkey, offset) or better yet both of:
        #  a=AES(readkey, offset=0)
        #  a.process(ciphertext, offset=xyz)
        # For now, we fake it with the existing iv= argument.
        offset_big = offset // 16
        offset_small = offset % 16
        iv = binascii.unhexlify("%032x" % offset_big)
        self._decryptor = AES(readkey, iv=iv)
        self._decryptor.process("\x00"*offset_small)

    def set_download_status_read_event(self, read_ev):
        self._read_ev = read_ev
    def set_download_status(self, ds):
        self._download_status = ds

    def registerProducer(self, producer, streaming):
        # this passes through, so the real consumer can flow-control the real
        # producer. Therefore we don't need to provide any IPushProducer
        # methods. We implement all the IConsumer methods as pass-throughs,
        # and only intercept write() to perform decryption.
        self._consumer.registerProducer(producer, streaming)
    def unregisterProducer(self):
        self._consumer.unregisterProducer()
    def write(self, ciphertext):
        started = now()
        plaintext = self._decryptor.process(ciphertext)
        if self._read_ev:
            elapsed = now() - started
            self._read_ev.update(0, elapsed, 0)
        if self._download_status:
            self._download_status.add_misc_event("AES", started, now())
        self._consumer.write(plaintext)
开发者ID:GunioRobot,项目名称:tahoe-lafs,代码行数:44,代码来源:filenode.py

示例8: _encrypt_and_encode

    def _encrypt_and_encode(self):
        # this returns a Deferred that fires with a list of (sharedata,
        # sharenum) tuples. TODO: cache the ciphertext, only produce the
        # shares that we care about.
        self.log("_encrypt_and_encode")

        self._status.set_status("Encrypting")
        started = time.time()

        key = hashutil.ssk_readkey_data_hash(self.salt, self.readkey)
        enc = AES(key)
        crypttext = enc.process(self.newdata)
        assert len(crypttext) == len(self.newdata)

        now = time.time()
        self._status.timings["encrypt"] = now - started
        started = now

        # now apply FEC

        self._status.set_status("Encoding")
        fec = codec.CRSEncoder()
        fec.set_params(self.segment_size,
                       self.required_shares, self.total_shares)
        piece_size = fec.get_block_size()
        crypttext_pieces = [None] * self.required_shares
        for i in range(len(crypttext_pieces)):
            offset = i * piece_size
            piece = crypttext[offset:offset+piece_size]
            piece = piece + "\x00"*(piece_size - len(piece)) # padding
            crypttext_pieces[i] = piece
            assert len(piece) == piece_size

        d = fec.encode(crypttext_pieces)
        def _done_encoding(res):
            elapsed = time.time() - started
            self._status.timings["encode"] = elapsed
            return res
        d.addCallback(_done_encoding)
        return d
开发者ID:ducki2p,项目名称:tahoe-lafs,代码行数:40,代码来源:publish.py

示例9: __init__

 def __init__(self, consumer, readkey, offset):
     self._consumer = consumer
     self._read_event = None
     # TODO: pycryptopp CTR-mode needs random-access operations: I want
     # either a=AES(readkey, offset) or better yet both of:
     #  a=AES(readkey, offset=0)
     #  a.process(ciphertext, offset=xyz)
     # For now, we fake it with the existing iv= argument.
     offset_big = offset // 16
     offset_small = offset % 16
     iv = binascii.unhexlify("%032x" % offset_big)
     self._decryptor = AES(readkey, iv=iv)
     self._decryptor.process("\x00"*offset_small)
开发者ID:ducki2p,项目名称:tahoe-lafs,代码行数:13,代码来源:filenode.py

示例10: aes

def aes(key, data, counter=False):
    """ encrypt data with aes, using either pycryptopp or PyCrypto.
        Args
            key: The encryption key
            data: plain text data
            counter: a callable, usually not needed
    """
    # using either pycryptopp...
    if hasattr(AES, "process"):
        a = AES(key)
        return a.process(data)
    # ... or PyCrypto
    counter = counter or Counter()
    a = AES.new(key, AES.MODE_CTR, counter=counter)
    rest = len(data) % 16
    if not rest:
        return a.encrypt(data)
    # Data length must be a multiple of 16
    # Pad with bytes all of the same value as the number of padding bytes
    pad = (16 - rest)
    data += chr(pad) * pad
    return a.encrypt(data)[:-pad]
开发者ID:HITGmbH,项目名称:py-convergent-encryption,代码行数:22,代码来源:crypto.py

示例11: _decrypt_privkey

 def _decrypt_privkey(self, enc_privkey):
     enc = AES(self._writekey)
     privkey = enc.process(enc_privkey)
     return privkey
开发者ID:drewp,项目名称:tahoe-lafs,代码行数:4,代码来源:filenode.py

示例12: _encrypt_privkey

 def _encrypt_privkey(self, writekey, privkey):
     enc = AES(writekey)
     crypttext = enc.process(privkey)
     return crypttext
开发者ID:drewp,项目名称:tahoe-lafs,代码行数:4,代码来源:filenode.py


注:本文中的pycryptopp.cipher.aes.AES类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。