python类decrypt()的实例源码

test_strings.py 文件源码 项目:secuimag3a 作者: matthiasbe 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_enc_dec(self):

        message = unicode_string.encode('utf-8')
        print("\tMessage:   %s" % message)

        encrypted = rsa.encrypt(message, self.pub)
        print("\tEncrypted: %s" % encrypted)

        decrypted = rsa.decrypt(encrypted, self.priv)
        print("\tDecrypted: %s" % decrypted)

        self.assertEqual(message, decrypted)
cli.py 文件源码 项目:secuimag3a 作者: matthiasbe 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
test_strings.py 文件源码 项目:secuimag3a 作者: matthiasbe 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_enc_dec(self):
        message = unicode_string.encode('utf-8')
        print("\tMessage:   %s" % message)

        encrypted = rsa.encrypt(message, self.pub)
        print("\tEncrypted: %s" % encrypted)

        decrypted = rsa.decrypt(encrypted, self.priv)
        print("\tDecrypted: %s" % decrypted)

        self.assertEqual(message, decrypted)
hk_rsa.py 文件源码 项目:CTF-chal-code 作者: zwhubuntu 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def decrypt(x,privkey):
    return rsa.decrypt(x,privkey)
rsa_aes.py 文件源码 项目:pupy 作者: ru-faraon 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def downstream_recv(self, data):
        try:
            enc=data.peek()
            if self._iv_dec is None: #receive IV
                if len(enc)<BLOCK_SIZE:
                    return
                self._iv_dec=enc[0:BLOCK_SIZE]
                if AES is not None:
                    self.dec_cipher = AES.new(self.aes_key, AES.MODE_CBC, self._iv_dec)
                else:
                    self.dec_cipher = pyaes.AESModeOfOperationCBC(self.aes_key, iv = self._iv_dec)
                data.drain(BLOCK_SIZE)
                enc=enc[BLOCK_SIZE:]
                if not enc:
                    return
            i=0
            cleartext=b""
            full_block=b""
            while True:
                if self.size_to_read is None:
                    if len(enc)<BLOCK_SIZE:
                        break
                    self.first_block=self.dec_cipher.decrypt(enc[0:BLOCK_SIZE])
                    data.drain(BLOCK_SIZE)
                    self.size_to_read=struct.unpack("<I", self.first_block[0:4])[0]
                    enc=enc[BLOCK_SIZE:]
                if self.size_to_read is None:
                    break
                if self.size_to_read <= len(self.first_block[4:]):
                    cleartext+=self.first_block[4:4+self.size_to_read] # the remaining data is padding, just drop it
                    self.size_to_read=None
                    self.first_block=b""
                    continue
                s=(self.size_to_read-len(self.first_block[4:]))
                blocks_to_read=s+(BLOCK_SIZE-(s%BLOCK_SIZE))
                if len(enc) < blocks_to_read:
                    break
                full_block=self.first_block[4:]+self.dec_cipher.decrypt(enc[:blocks_to_read])
                cleartext+=full_block[0:self.size_to_read] # the remaining data is padding, just drop it
                enc=enc[blocks_to_read:]
                data.drain(blocks_to_read)
                self.size_to_read=None
                self.first_block=b""
            self.upstream.write(cleartext)
        except Exception as e:
            logging.debug(traceback.format_exc())


问题


面经


文章

微信
公众号

扫码关注公众号