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


Python Cipher.PKCS1_OAEP类代码示例

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


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

示例1: decrypt

    def decrypt(self, ciphertext, key, padding="pkcs1_padding"):
        if padding == "pkcs1_padding":
            cipher = PKCS1_v1_5.new(key)
            if self.with_digest:
                dsize = SHA.digest_size
            else:
                dsize = 0
            sentinel = Random.new().read(32 + dsize)
            text = cipher.decrypt(ciphertext, sentinel)
            if dsize:
                _digest = text[-dsize:]
                _msg = text[:-dsize]
                digest = SHA.new(_msg).digest()
                if digest == _digest:
                    text = _msg
                else:
                    raise DecryptionFailed()
            else:
                if text == sentinel:
                    raise DecryptionFailed()
        elif padding == "pkcs1_oaep_padding":
            cipher = PKCS1_OAEP.new(key)
            text = cipher.decrypt(ciphertext)
        else:
            raise Exception("Unsupported padding")

        return text
开发者ID:techguy613,项目名称:pyjwkest,代码行数:27,代码来源:jwe.py

示例2: encryptDataWithPubKey

def encryptDataWithPubKey(data, pubKeyFile=RSA_pubKeyFile, outFile=None):
    from Cryptodome.PublicKey   import RSA
    from Cryptodome.Random      import get_random_bytes
    from Cryptodome.Cipher      import AES, PKCS1_OAEP


    recipient_key   = RSA.import_key(open(pubKeyFile).read())
    session_key     = get_random_bytes(16)

        # Encrypt the session key with the public RSA key
    cipher_rsa      = PKCS1_OAEP.new(recipient_key)


        # Encrypt the data with the AES session key
    cipher_aes = AES.new(session_key, AES.MODE_EAX)
    ciphertext, tag = cipher_aes.encrypt_and_digest(data)
    print ()
    print (ciphertext)
    print ()
    print (tag)
    print ()
    if outFile:
        file_out = open(outFile, "wb")
        file_out.write(cipher_rsa.encrypt(session_key))
        [ file_out.write(x) for x in (ciphertext.nonce, tag, ciphertext) ]
开发者ID:Loreton,项目名称:LnPythonLib,代码行数:25,代码来源:GenerateRSAKeys.py

示例3: encrypt

    def encrypt(self, message):
        if isinstance(message, unicode):
            message = message.encode('utf8')

        cipher = PKCS1_OAEP.new(self.key)
        encryptedMessage = cipher.encrypt(message)
        return base64.b64encode(encryptedMessage)
开发者ID:szatanszmatan,项目名称:myrdp,代码行数:7,代码来源:crypto.py

示例4: encrypt

 def encrypt(self, msg, key, padding="pkcs1_padding"):
     if padding == "pkcs1_padding":
         cipher = PKCS1_v1_5.new(key)
         if self.with_digest:  # add a SHA digest to the message
             h = SHA.new(msg)
             msg += h.digest()
     elif padding == "pkcs1_oaep_padding":
         cipher = PKCS1_OAEP.new(key)
     else:
         raise Exception("Unsupported padding")
     return cipher.encrypt(msg)
开发者ID:techguy613,项目名称:pyjwkest,代码行数:11,代码来源:jwe.py

示例5: signature

def signature(email, password, key):
    signature = bytearray(b'\x00')

    struct = key_to_struct(key)
    signature.extend(hashlib.sha1(struct).digest()[:4])

    cipher = PKCS1_OAEP.new(key)
    encrypted_login = cipher.encrypt((email + u'\x00' + password).encode('utf-8'))

    signature.extend(encrypted_login)

    return base64.urlsafe_b64encode(signature)
开发者ID:Geka000,项目名称:gpsoauth,代码行数:12,代码来源:google.py

示例6: add_issuer_key

 def add_issuer_key(self, private_key):
     """
     Adds a private key to the list of keys available for decryption
     and signatures
     :return: Boolean - Whether the key is already in the list
     """
     new_key = RSAKey(key=import_rsa_key(private_key),
                      kid=self.__generate_key_id(private_key))
     for key in self.issuer_private_keys:
         if new_key.kid == key.kid:
             return False
     self.issuer_private_keys.append(new_key)
     self.loaded_issuer_private_keys[new_key.kid] = PKCS1_OAEP.new(
         RSA.importKey(private_key))
     return True
开发者ID:LaunchKey,项目名称:launchkey-python,代码行数:15,代码来源:jose_auth.py

示例7: parse_key_response

    def parse_key_response(self, headerdata):
        # Init Decryption
        enc_key = headerdata['keyresponsedata']['keydata']['encryptionkey']
        hmac_key = headerdata['keyresponsedata']['keydata']['hmackey']
        encrypted_encryption_key = base64.standard_b64decode(enc_key)
        encrypted_sign_key = base64.standard_b64decode(hmac_key)
        cipher_rsa = PKCS1_OAEP.new(self.rsa_key)

        # Decrypt encryption key
        cipher_raw = cipher_rsa.decrypt(encrypted_encryption_key)
        encryption_key_data = json.JSONDecoder().decode(cipher_raw)
        self.encryption_key = self.__base64key_decode(encryption_key_data['k'])

        # Decrypt sign key
        sign_key_raw = cipher_rsa.decrypt(encrypted_sign_key)
        sign_key_data = json.JSONDecoder().decode(sign_key_raw)
        self.sign_key = self.__base64key_decode(sign_key_data['k'])
开发者ID:dumpster-of-things,项目名称:plugin.video.netflix,代码行数:17,代码来源:MSLCrypto.py

示例8: PKCS1_OAEP_AES_decrypt

    def PKCS1_OAEP_AES_decrypt(self, data, inpFile):


        file_in = open(inpFile, "rb")

        private_key = self._privateKey

        enc_session_key, nonce, tag, ciphertext = [ file_in.read(x) for x in (private_key.size_in_bytes(), 16, 16, -1) ]

        # Decrypt the session key with the public RSA key
        cipher_rsa = PKCS1_OAEP.new(private_key)
        session_key = cipher_rsa.decrypt(enc_session_key)

        # Decrypt the data with the AES session key
        cipher_aes = AES.new(session_key, AES.MODE_EAX, nonce)
        data = cipher_aes.decrypt_and_verify(ciphertext, tag)


        return data
开发者ID:Loreton,项目名称:LnPythonLib,代码行数:19,代码来源:LnRSA_Class.py

示例9: PKCS1_OAEP_AES_encrypt

    def PKCS1_OAEP_AES_encrypt(self, data, outFile):


            # recipient_key = Crypto.PublicKey.RSA.import_key(open("receiver.pem").read())
        recipient_key = self._privateKey
        session_key = Random.get_random_bytes(32)

            # Encrypt the session key with the public RSA key
        cipher_rsa = PKCS1_OAEP.new(recipient_key)

            # Encrypt the data with the AES session key
        cipher_aes = AES.new(session_key, AES.MODE_EAX)
        ciphertext, tag = cipher_aes.encrypt_and_digest(data)

            # creazione del file con i dati crypted
        print ('file {FILE} has been created with encrypted data.'.format(FILE=outFile))
        file_out = open(outFile, "wb")
        file_out.write(cipher_rsa.encrypt(session_key))
        [ file_out.write(x) for x in (cipher_aes.nonce, tag, ciphertext) ]

        return ciphertext
开发者ID:Loreton,项目名称:LnPythonLib,代码行数:21,代码来源:LnRSA_Class.py

示例10: decrypt

 def decrypt(self, encryptedMessage):
     cipher = PKCS1_OAEP.new(self.key)
     if encryptedMessage is None:
         return None
     decryptedMessage = cipher.decrypt(base64.b64decode(encryptedMessage))
     return decryptedMessage.decode('utf8')
开发者ID:szatanszmatan,项目名称:myrdp,代码行数:6,代码来源:crypto.py

示例11: decrypt_PKCS1_OAEP

    def decrypt_PKCS1_OAEP(self, ciphertext):
        key = self._privateKey
        cipher = PKCS1_OAEP.new(key)
        message = cipher.decrypt(ciphertext)

        return message
开发者ID:Loreton,项目名称:LnPythonLib,代码行数:6,代码来源:LnRSA_Class.py

示例12: encrypt_PKCS1_OAEP

    def encrypt_PKCS1_OAEP(self, message):
        key = self._publicKey
        cipher = PKCS1_OAEP.new(key)
        ciphertext = cipher.encrypt(message)

        return ciphertext
开发者ID:Loreton,项目名称:LnPythonLib,代码行数:6,代码来源:LnRSA_Class.py

示例13:

 def testEncryptDecrypt3(self):
         # Verify that OAEP supports labels
         pt = self.rng(35)
         xlabel = self.rng(22)
         cipher = PKCS.new(self.key1024, label=xlabel)
         ct = cipher.encrypt(pt)
         self.assertEqual(cipher.decrypt(ct), pt)
开发者ID:FndNur1Labs,项目名称:PokemonGo-DesktopMap,代码行数:7,代码来源:test_pkcs1_oaep.py

示例14: xrange

 def testEncryptDecrypt1(self):
         # Encrypt/Decrypt messages of length [0..128-2*20-2]
         for pt_len in xrange(0,128-2*20-2):
             pt = self.rng(pt_len)
             cipher = PKCS.new(self.key1024)
             ct = cipher.encrypt(pt)
             pt2 = cipher.decrypt(ct)
             self.assertEqual(pt,pt2)
开发者ID:FndNur1Labs,项目名称:PokemonGo-DesktopMap,代码行数:8,代码来源:test_pkcs1_oaep.py

示例15: long

 def testDecrypt1(self):
         # Verify decryption using all test vectors
         for test in self._testData:
                 # Build the key
                 comps = [ long(rws(test[0][x]),16) for x in ('n','e','d') ]
                 key = RSA.construct(comps)
                 # The real test
                 cipher = PKCS.new(key, test[4])
                 pt = cipher.decrypt(t2b(test[2]))
                 self.assertEqual(pt, t2b(test[1]))
开发者ID:FndNur1Labs,项目名称:PokemonGo-DesktopMap,代码行数:10,代码来源:test_pkcs1_oaep.py


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