Python rsa 模块,decrypt() 实例源码

我们从Python开源项目中,提取了以下35个代码示例,用于说明如何使用rsa.decrypt()

项目:AshsSDK    作者:thehappydinoa    | 项目源码 | 文件源码
def add_to_params(self, parameters, value):
        """
        This gets called with the value of our ``--priv-launch-key``
        if it is specified.  It needs to determine if the path
        provided is valid and, if it is, it stores it in the instance
        variable ``_key_path`` for use by the decrypt routine.
        """
        if value:
            path = os.path.expandvars(value)
            path = os.path.expanduser(path)
            if os.path.isfile(path):
                self._key_path = path
                endpoint_prefix = \
                    self._operation_model.service_model.endpoint_prefix
                event = 'after-call.%s.%s' % (endpoint_prefix,
                                              self._operation_model.name)
                self._session.register(event, self._decrypt_password_data)
            else:
                msg = ('priv-launch-key should be a path to the '
                       'local SSH private key file used to launch '
                       'the instance.')
                raise ValueError(msg)
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def downstream_recv(self, data):
        try:
            enc=data.peek()
            if self.aes_key is None: #receive aes key
                if len(enc) < self.rsa_key_size/8:
                    return
                cmsg=enc[:self.rsa_key_size/8]
                try:
                    self.aes_key=rsa.decrypt(cmsg, self.pk)
                except rsa.pkcs1.DecryptionError:
                    self.close()
                    return
                data.drain(self.rsa_key_size/8)

                if AES is not None:
                    self.enc_cipher = AES.new(self.aes_key, AES.MODE_CBC, self._iv_enc)
                else:
                    self.enc_cipher = pyaes.AESModeOfOperationCBC(self.aes_key, iv = self._iv_enc)
            super(RSA_AESServer, self).downstream_recv(data)
        except Exception as e:
            logging.debug(e)
项目:dreamr-botnet    作者:YinAndYangSecurityAwareness    | 项目源码 | 文件源码
def decryptAndVerify(self, ciphertextPickle, senderPublic):
        try:
            if (ciphertextPickle):
                decoded = pickle.loads(ciphertextPickle)
                if (decoded):
                    signature = decoded[0]
                    content = decoded[1]
                    if (rsa.verify(content, signature, senderPublic)):
                        debug("crypt", "Message signature was verified. Decrypting..")
                        return rsa.decrypt(content, self.DRMPrivateKey)
            else:
                debug("crypt", "Message was empty. \"No Updates\"")
        except Exception as e:
            debug("crypt", "Error decrypting message. -> %s" % str(e))

    # Load the keys
项目:YY    作者:gamegrd    | 项目源码 | 文件源码
def on_handshake_respone(self, recv_buffer):
        proto = YYProto_pb2.YYProto()
        proto.ParseFromString(recv_buffer[4:])
        #hexdump.hexdump(proto.key_ack.rsa_key)
        try:
            rc4_key = rsa.decrypt(proto.key_ack.rsa_key, self.rsa_pri_key)
        except:

            print 'decode key error username %s' % (self.username)
            self.state = YY_CLIENT_WAITING
            self.stream.close()
            return
        self.rc4_e = RC4(rc4_key)
        self.rc4_d = RC4(rc4_key)
        #print 'rc4_key'
        #hexdump.hexdump(rc4_key)
        self.login_request()
项目:flora    作者:Lamden    | 项目源码 | 文件源码
def post(self):
        payload = {
            'owner' : request.form['owner'],
            'package' : request.form['package'],
            'data' : request.form['data']
        }

        owner = request.form['owner']
        package = request.form['package']
        data = request.form['data']
        b = ENGINE.get_named_secret(owner)
        print(b)
        secret = rsa.decrypt(eval(b), KEY[1])

        # data is a python tuple of the templated solidity at index 0 and an example payload at index 1
        # compilation of this code should return true
        # if there are errors, don't commit it to the db
        # otherwise, commit it
        raw_data = decrypt(secret, eval(data))
        package_data = json.loads(raw_data.decode('utf8'))
        '''
        payload = {
            'tsol' : open(code_path[0]).read(),
            'example' : example
        }
        '''

        # assert that the code compiles with the provided example
        tsol.compile(StringIO(package_data['tsol']), package_data['example'])

        template = pickle.dumps(package_data['tsol'])
        example = pickle.dumps(package_data['example'])

        if ENGINE.add_package(owner, package, template, example) == True:
            return success_payload(None, 'Package successfully uploaded.')
        return error_payload('Problem uploading package. Try again.')
项目:oscars2016    作者:0x0ece    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        '''Decrypts files.'''

        return rsa.decrypt(indata, priv_key)
项目:GAMADV-XTD    作者:taers232c    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
项目:zeronet-debian    作者:bashrc    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        '''Decrypts files.'''

        return rsa.decrypt(indata, priv_key)
项目:plugin.video.bdyun    作者:caasiu    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
项目:WeiboPictureWorkflow    作者:cielpy    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
项目:AshsSDK    作者:thehappydinoa    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
项目:AshsSDK    作者:thehappydinoa    | 项目源码 | 文件源码
def _decrypt_password_data(self, parsed, **kwargs):
        """
        This handler gets called after the GetPasswordData command has been
        executed.  It is called with the and the ``parsed`` data.  It checks to
        see if a private launch key was specified on the command.  If it was,
        it tries to use that private key to decrypt the password data and
        replace it in the returned data dictionary.
        """
        if self._key_path is not None:
            logger.debug("Decrypting password data using: %s", self._key_path)
            value = parsed.get('PasswordData')
            if not value:
                return
            try:
                with open(self._key_path) as pk_file:
                    pk_contents = pk_file.read()
                    private_key = rsa.PrivateKey.load_pkcs1(six.b(pk_contents))
                    value = base64.b64decode(value)
                    value = rsa.decrypt(value, private_key)
                    logger.debug(parsed)
                    parsed['PasswordData'] = value.decode('utf-8')
                    logger.debug(parsed)
            except Exception:
                logger.debug('Unable to decrypt PasswordData', exc_info=True)
                msg = ('Unable to decrypt password data using '
                       'provided private key file.')
                raise ValueError(msg)
项目:REMAP    作者:REMAPApp    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
项目:OneClickDTU    作者:satwikkansal    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        '''Decrypts files.'''

        return rsa.decrypt(indata, priv_key)
项目:dreamr-botnet    作者:YinAndYangSecurityAwareness    | 项目源码 | 文件源码
def encryptAndSign(self, plaintext, recipientPublic):
        try:
            content = rsa.encrypt(plaintext, recipientPublic)
            signature = rsa.sign(content, self.DRMPrivateKey, "SHA-1")
            return pickle.dumps([signature, content])
        except Exception as e:
            debug("crypt", "Failed encrypting the message. -> %s" % str(e))
        return

    # Verify signature with sender's public key, then proceed to use
    # our own private key to decrypt the message
    # pass the expected timestamp, to thawrt rplay attacks. gets cryptd
项目:metrics    作者:Jeremy-Friedman    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
项目:metrics    作者:Jeremy-Friedman    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
项目:alfredToday    作者:jeeftor    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
项目:gmail_scanner    作者:brandonhub    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
项目:teleport    作者:eomsoft    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        '''Decrypts files.'''

        return rsa.decrypt(indata, priv_key)
项目:GAMADV-X    作者:taers232c    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
项目:blue_fariy    作者:lcatro    | 项目源码 | 文件源码
def rsa_decrypt(private_key,data) :
    try :
        decrypt_string=''

        while len(data)>128 :  #  RSA Decrypt byte once ..
            decrypt_string+=rsa.decrypt(data[:128],private_key)
            data=data[128:]
        decrypt_string+=rsa.decrypt(data,private_key)

        return decrypt_string
    except :
        return None
项目:blue_fariy    作者:lcatro    | 项目源码 | 文件源码
def print_help() :
    print 'Using :'
    print ''
    print '    bule_fariy.py encrypt|decrypt'
    print ''
    print '    bule_fariy.py encrypt    encrypt current path all file'
    print '    bule_fariy.py decrypt    decrypt current path all file'
项目:safetalk    作者:zjuchenyuan    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
项目:safetalk    作者:zjuchenyuan    | 项目源码 | 文件源码
def decrypt_hismessage(mypriv=None):
    """
    Try to decrypt his message using mypriv
    return message if success else False
    """
    if mypriv is None:
        mypriv = storage_get("mypriv")
    try:
        rawdata = clipboard_read()
        crypto = d64(rawdata)
        message = rsa.decrypt(crypto, mypriv)
        return message
    except:
        return False
项目:rsplus    作者:zoxuyu    | 项目源码 | 文件源码
def decrypt_assistant():
    cname = input("Bitte gebe den Pfad zur .crypt-Datei an: ")
    if cname.split(".")[-1] != "crypt":
        print("Keine Crypt-Datei angegeben.")
        return
    c = open(cname, "r")
    crypt = c.read()
    c.close()
    fname = '.'.join(cname.split(".")[:-1])

    print("Die Datei wird entschlüsselt.")
    crypt, name = unarmor("RSPLUS OUTPUT", crypt)
    crypt = ''.join(crypt.split("\n"))
    crypt = str(base64.b64decode(bytes(crypt, "utf-8")), "utf-8")

    passw = getpass("Für ihren privaten Schlüssel benötigen wir ein Passwort: ")

    names = prikr.gets(passw)
    if not name in names:
        print("You do not have the private key to encrypt.")
        return
    print("Entschlüssele (dauert einen Moment)")

    msg = str(bytes(rsa.decrypt(crypt, prikr.get(name, passw)).strip("b'"), "utf-8"), "utf-8")
    print(msg)
    msg = eval("'''" + msg + "'''")
    f = open(fname, "w")
    f.write(msg)
    f.close()
项目:rsplus    作者:zoxuyu    | 项目源码 | 文件源码
def decrypt_assistant():
    cname = input("Bitte gebe den Pfad zur .crypt-Datei an: ")
    if cname.split(".")[-1] != "crypt":
        print("Keine Crypt-Datei angegeben.")
        return
    c = open(cname, "r")
    crypt = c.read()
    c.close()
    fname = '.'.join(cname.split(".")[:-1])

    print("Die Datei wird entschlüsselt.")
    crypt, name = unarmor("RSPLUS OUTPUT", crypt)
    crypt = ''.join(crypt.split("\n"))
    crypt = str(base64.b64decode(bytes(crypt, "utf-8")), "utf-8")

    passw = getpass("Für ihren privaten Schlüssel benötigen wir ein Passwort: ")

    names = prikr.gets(passw)
    if not name in names:
        print("You do not have the private key to encrypt.")
        return
    print("Entschlüssele (dauert einen Moment)")

    msg = str(bytes(rsa.decrypt(crypt, prikr.get(name, passw)).strip("b'"), "utf-8"), "utf-8")
    print(msg)
    msg = eval("'''" + msg + "'''")
    f = open(fname, "w")
    f.write(msg)
    f.close()
项目:python-rsa    作者:sybrenstuvel    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
项目:python-rsa    作者:sybrenstuvel    | 项目源码 | 文件源码
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)
项目:secuimag3a    作者:matthiasbe    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        '''Decrypts files.'''

        return rsa.decrypt(indata, priv_key)
项目:secuimag3a    作者:matthiasbe    | 项目源码 | 文件源码
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)
项目:secuimag3a    作者:matthiasbe    | 项目源码 | 文件源码
def perform_operation(self, indata, priv_key, cli_args=None):
        """Decrypts files."""

        return rsa.decrypt(indata, priv_key)
项目:secuimag3a    作者:matthiasbe    | 项目源码 | 文件源码
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)
项目:CTF-chal-code    作者:zwhubuntu    | 项目源码 | 文件源码
def decrypt(x,privkey):
    return rsa.decrypt(x,privkey)
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
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())