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


Python PKCS1_v1_5.new方法代码示例

本文整理汇总了Python中Crypto.Cipher.PKCS1_v1_5.new方法的典型用法代码示例。如果您正苦于以下问题:Python PKCS1_v1_5.new方法的具体用法?Python PKCS1_v1_5.new怎么用?Python PKCS1_v1_5.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crypto.Cipher.PKCS1_v1_5的用法示例。


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

示例1: testEncrypt1

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def testEncrypt1(self):
                for test in self._testData:
                        # Build the key
                        key = RSA.importKey(test[0])
                        # RNG that takes its random numbers from a pool given
                        # at initialization
                        class randGen:
                            def __init__(self, data):
                                self.data = data
                                self.idx = 0
                            def __call__(self, N):
                                r = self.data[self.idx:N]
                                self.idx += N
                                return r
                        # The real test
                        key._randfunc = randGen(t2b(test[3]))
                        cipher = PKCS.new(key)
                        ct = cipher.encrypt(b(test[1]))
                        self.assertEqual(ct, t2b(test[2])) 
开发者ID:mortcanty,项目名称:earthengine,代码行数:21,代码来源:test_pkcs1_15.py

示例2: signRSA

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def signRSA(message, privatekey, hashAlg):

    global hash1
    hash1 = hashAlg
    signer = PKCS1_v1_5.new(privatekey)
    if (hash1 == "SHA-512"):
        digest = SHA512.new()
    elif (hash1 == "SHA-384"):
        digest = SHA384.new()
    elif (hash1 == "SHA-256"):
        digest = SHA256.new()
    elif (hash1 == "SHA-1"):
        digest = SHA.new()
    else:
        digest = MD5.new()
    digest.update(message)
    return signer.sign(digest) 
开发者ID:lockedbyte,项目名称:cryptovenom,代码行数:19,代码来源:main.py

示例3: __init__

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def __init__(self, key_pair, passphrase=None, cipher=utils.AESCTRCipher(), mat_desc=None):

        super(RsaProvider, self).__init__(cipher=cipher, mat_desc=mat_desc)
        self.wrap_alg = headers.RSA_NONE_PKCS1Padding_WRAP_ALGORITHM

        if key_pair and not isinstance(key_pair, dict):
            raise ClientError('Invalid type, the type of key_pair must be dict!')

        try:
            if 'public_key' in key_pair:
                self.__encrypt_obj = PKCS1_v1_5.new(RSA.importKey(key_pair['public_key'], passphrase=passphrase))

            if 'private_key' in key_pair:
                self.__decrypt_obj = PKCS1_v1_5.new(RSA.importKey(key_pair['private_key'], passphrase=passphrase))
        except (ValueError, TypeError) as e:
            raise ClientError(str(e)) 
开发者ID:aliyun,项目名称:aliyun-oss-python-sdk,代码行数:18,代码来源:crypto.py

示例4: SignWith3Des

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def SignWith3Des(src):
    # 首先对字符串取MD5
    raw_buf = hashlib.md5(src.encode()).digest()
    # 对16字节的md5做bcd2ascii
    bcd_to_ascii = bytearray(32)
    for i in range(len(raw_buf)):
        bcd_to_ascii[2*i]   = raw_buf[i]>>4
        bcd_to_ascii[2*i+1] = raw_buf[i] & 0xf
    # hex_to_bin转换加密key
    key = bytes.fromhex('3ECA2F6FFA6D4952ABBACA5A7B067D23')
    # 对32字节的bcd_to_ascii做Triple DES加密(3DES/ECB/NoPadding)
    des3 = DES3.new(key, DES3.MODE_ECB)
    enc_bytes = des3.encrypt(bcd_to_ascii)
    # bin_to_hex得到最终加密结果
    enc_buf = ''.join(["%02X" % x for x in enc_bytes]).strip()
    return enc_buf

# 根据svrid查询client_msg_id 
开发者ID:wechat-tests,项目名称:PyMicroChat,代码行数:20,代码来源:Util.py

示例5: decrypt

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def decrypt(cls, data):
        if RsaCrypt.CHIPPER is None:
            rsa = SysConfig.get_init_rsa_obj()
            RsaCrypt.CHIPPER = Cipher_pkcs1.new(rsa)

        # 1024 bit的证书用128,2048 bit证书用256位
        one_len = 128
        ret_data = b''

        # python2下需转成str类型,否则异常
        if IS_PY2:
            data = str(data)

        for i in range(0, len(data), one_len):
            ret_data += RsaCrypt.CHIPPER.decrypt(data[i:i + one_len], RsaCrypt.RANDOM_GENERATOR)

        return ret_data 
开发者ID:FutunnOpen,项目名称:futuquant,代码行数:19,代码来源:sys_config.py

示例6: get_client_proof

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def get_client_proof(clientnonce, servernonce, password, salt, iterations):
    """ calculates server client proof (part of the SCRAM algorithm) """
    msg = "%s,%s,%s" % (clientnonce, servernonce, servernonce)
    salted_pass = hashlib.pbkdf2_hmac(
        'sha256', password.encode('utf_8'), bytearray.fromhex(salt), iterations)
    client_key = hmac.new(b'Client Key', msg=salted_pass,
                        digestmod=hashlib.sha256)
    stored_key = hashlib.sha256()
    stored_key.update(client_key.digest())
    signature = hmac.new(msg.encode('utf_8'),
                        msg=stored_key.digest(), digestmod=hashlib.sha256)
    client_key_digest = client_key.digest()
    signature_digest = signature.digest()
    client_proof = bytearray()
    i = 0
    while i < client_key.digest_size:
        client_proof.append(client_key_digest[i] ^ signature_digest[i])
        i = i + 1
    return hexlify(client_proof) 
开发者ID:jinxo13,项目名称:HuaweiB525Router,代码行数:21,代码来源:crypto.py

示例7: rsa_encrypt

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def rsa_encrypt(rsae, rsan, data):
    if (data is None or data == ''): return ''
    N = int(rsan,16)
    E = int(rsae,16)
    b64data = base64.b64encode(data)
    pubkey = construct((N, E))
    cipher = PKCS1_v1_5.new(pubkey)
    blocks = int(math.ceil(len(b64data) / 245.0))
    result = []
    for i in range(blocks):
        block = b64data[i*245:(i+1)*245]
        d = cipher.encrypt(block)
        result.append(d)
    result = hexlify(''.join(result))
    if ((len(result) & 1) == 0):
        return result
    else:
        return '0'+result 
开发者ID:jinxo13,项目名称:HuaweiB525Router,代码行数:20,代码来源:crypto.py

示例8: testEncrypt1

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def testEncrypt1(self):
                for test in self._testData:
                        # Build the key
                        key = RSA.importKey(test[0])
                        # RNG that takes its random numbers from a pool given
                        # at initialization
                        class randGen:
                            def __init__(self, data):
                                self.data = data
                                self.idx = 0
                            def __call__(self, N):
                                r = self.data[self.idx:self.idx+N]
                                self.idx += N
                                return r
                        # The real test
                        cipher = PKCS.new(key, randfunc=randGen(t2b(test[3])))
                        ct = cipher.encrypt(b(test[1]))
                        self.assertEqual(ct, t2b(test[2])) 
开发者ID:vcheckzen,项目名称:FODI,代码行数:20,代码来源:test_pkcs1_15.py

示例9: encrypt

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def encrypt(payload, public_key):
        """
        Encrypt a payload using an encrypted JSON wrapper.

        See: https://diaspora.github.io/diaspora_federation/federation/encryption.html

        :param payload: Payload document as a string.
        :param public_key: Public key of recipient as an RSA object.
        :return: Encrypted JSON wrapper as dict.
        """
        iv, key, encrypter = EncryptedPayload.get_iv_key_encrypter()
        aes_key_json = EncryptedPayload.get_aes_key_json(iv, key)
        cipher = PKCS1_v1_5.new(public_key)
        aes_key = b64encode(cipher.encrypt(aes_key_json))
        padded_payload = pkcs7_pad(payload.encode("utf-8"), AES.block_size)
        encrypted_me = b64encode(encrypter.encrypt(padded_payload))
        return {
            "aes_key": aes_key.decode("utf-8"),
            "encrypted_magic_envelope": encrypted_me.decode("utf8"),
        } 
开发者ID:jaywink,项目名称:federation,代码行数:22,代码来源:encrypted.py

示例10: hash_token

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def hash_token(self):
        try:
            from Crypto.Hash import SHA1, HMAC
            command = "{}".format(CMD_GET_KEY)
            enc_command = await self.encrypt(command)
            await self._ws.send(enc_command)
            message = await self._ws.recv()
            await self.parse_loxone_message(message)
            message = await self._ws.recv()
            resp_json = json.loads(message)
            if 'LL' in resp_json:
                if "value" in resp_json['LL']:
                    key = resp_json['LL']['value']
                    if key != "":
                        digester = HMAC.new(binascii.unhexlify(key),
                                            self._token.token.encode("utf-8"), SHA1)
                        return digester.hexdigest()
            return ERROR_VALUE
        except:
            return ERROR_VALUE 
开发者ID:JoDehli,项目名称:PyLoxone,代码行数:22,代码来源:__init__.py

示例11: rws

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def rws(t):
    """Remove white spaces, tabs, and new lines from a string"""
    for c in ['\n', '\t', ' ']:
        t = t.replace(c,'')
    return t 
开发者ID:mortcanty,项目名称:earthengine,代码行数:7,代码来源:test_pkcs1_15.py

示例12: setUp

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def setUp(self):
                self.rng = Random.new().read
                self.key1024 = RSA.generate(1024, self.rng)

        # List of tuples with test data for PKCS#1 v1.5.
        # Each tuple is made up by:
        #       Item #0: dictionary with RSA key component, or key to import
        #       Item #1: plaintext
        #       Item #2: ciphertext
        #       Item #3: random data 
开发者ID:mortcanty,项目名称:earthengine,代码行数:12,代码来源:test_pkcs1_15.py

示例13: testEncrypt2

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def testEncrypt2(self):
                # Verify that encryption fail if plaintext is too long
                pt = '\x00'*(128-11+1)
                cipher = PKCS.new(self.key1024)
                self.assertRaises(ValueError, cipher.encrypt, pt) 
开发者ID:mortcanty,项目名称:earthengine,代码行数:7,代码来源:test_pkcs1_15.py

示例14: testVerify1

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def testVerify1(self):
                for test in self._testData:
                        # Build the key
                        key = RSA.importKey(test[0])
                        # The real test
                        cipher = PKCS.new(key)
                        pt = cipher.decrypt(t2b(test[2]), "---")
                        self.assertEqual(pt, b(test[1])) 
开发者ID:mortcanty,项目名称:earthengine,代码行数:10,代码来源:test_pkcs1_15.py

示例15: testEncryptVerify1

# 需要导入模块: from Crypto.Cipher import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Cipher.PKCS1_v1_5 import new [as 别名]
def testEncryptVerify1(self):
                # Encrypt/Verify messages of length [0..RSAlen-11]
                # and therefore padding [8..117]
                for pt_len in xrange(0,128-11+1):
                    pt = self.rng(pt_len)
                    cipher = PKCS.new(self.key1024)
                    ct = cipher.encrypt(pt)
                    pt2 = cipher.decrypt(ct, "---")
                    self.assertEqual(pt,pt2) 
开发者ID:mortcanty,项目名称:earthengine,代码行数:11,代码来源:test_pkcs1_15.py


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