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


Python RSA.construct方法代码示例

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


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

示例1: privatekeyblob_to_pkcs1

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def privatekeyblob_to_pkcs1(key):
    '''
    parse private key into pkcs#1 format
    :param key:
    :return:
    '''
    modulus = bytes_to_long(key['modulus'][::-1]) # n
    prime1 = bytes_to_long(key['prime1'][::-1]) # p
    prime2 = bytes_to_long(key['prime2'][::-1]) # q
    exp1 = bytes_to_long(key['exponent1'][::-1])
    exp2 = bytes_to_long(key['exponent2'][::-1])
    coefficient = bytes_to_long(key['coefficient'][::-1])
    privateExp = bytes_to_long(key['privateExponent'][::-1]) # d
    if PY3:
        long = int
    pubExp = long(key['rsapubkey']['pubexp']) # e
    # RSA.Integer(prime2).inverse(prime1) # u

    r = RSA.construct((modulus, pubExp, privateExp, prime1, prime2))
    return r 
开发者ID:Coalfire-Research,项目名称:Slackor,代码行数:22,代码来源:dpapi.py

示例2: testEncrypt1

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def testEncrypt1(self):
                # Verify encryption using all test vectors
                for test in self._testData:
                        # Build the key
                        comps = [ int(rws(test[0][x]),16) for x in ('n','e') ]
                        key = RSA.construct(comps)
                        # 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
                        cipher = PKCS.new(key, test[4], randfunc=randGen(t2b(test[3])))
                        ct = cipher.encrypt(t2b(test[1]))
                        self.assertEqual(ct, t2b(test[2])) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:22,代码来源:test_pkcs1_oaep.py

示例3: testEncrypt1

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def testEncrypt1(self):
                # Verify encryption using all test vectors
                for test in self._testData:
                        # Build the key
                        comps = [ long(rws(test[0][x]),16) for x in ('n','e') ]
                        key = RSA.construct(comps)
                        # 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
                        cipher = PKCS.new(key, test[4], randfunc=randGen(t2b(test[3])))
                        ct = cipher.encrypt(t2b(test[1]))
                        self.assertEqual(ct, t2b(test[2])) 
开发者ID:mchristopher,项目名称:PokemonGo-DesktopMap,代码行数:22,代码来源:test_pkcs1_oaep.py

示例4: decryptKey

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def decryptKey(encryptedKey):
 """Decrypts an RSA-encrypted key"""
 rsa = RSA.construct((long(constants.rsaModulus), long(constants.rsaExponent)))
 try:
  return rsa.encrypt(encryptedKey, 0)[0]
 except NotImplementedError:
  # pycryptodome
  return long_to_bytes(rsa._encrypt(bytes_to_long(encryptedKey))) 
开发者ID:ma1co,项目名称:Sony-PMCA-RE,代码行数:10,代码来源:__init__.py

示例5: rsa_publickey

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def rsa_publickey(mod, exp):
    return rsa_construct((mod, exp)) 
开发者ID:ValvePython,项目名称:steam,代码行数:4,代码来源:crypto.py

示例6: key_from_b64

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def key_from_b64(b64_key):
    binaryKey = base64.b64decode(b64_key)

    i = bytes_to_long(binaryKey[:4])
    mod = bytes_to_long(binaryKey[4:4+i])

    j = bytes_to_long(binaryKey[i+4:i+4+4])
    exponent = bytes_to_long(binaryKey[i+8:i+8+j])

    key = RSA.construct((mod, exponent))

    return key 
开发者ID:simon-weber,项目名称:gpsoauth,代码行数:14,代码来源:google.py

示例7: testExportKey1

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def testExportKey1(self):
        key = RSA.construct([self.n, self.e, self.d, self.p, self.q, self.pInv])
        derKey = key.exportKey("DER")
        self.assertEqual(derKey, self.rsaKeyDER) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:6,代码来源:test_import_RSA.py

示例8: testExportKey2

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def testExportKey2(self):
        key = RSA.construct([self.n, self.e])
        derKey = key.exportKey("DER")
        self.assertEqual(derKey, self.rsaPublicKeyDER) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:6,代码来源:test_import_RSA.py

示例9: testExportKey3

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def testExportKey3(self):
        key = RSA.construct([self.n, self.e, self.d, self.p, self.q, self.pInv])
        pemKey = key.exportKey("PEM")
        self.assertEqual(pemKey, b(self.rsaKeyPEM)) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:6,代码来源:test_import_RSA.py

示例10: testExportKey4

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def testExportKey4(self):
        key = RSA.construct([self.n, self.e])
        pemKey = key.exportKey("PEM")
        self.assertEqual(pemKey, b(self.rsaPublicKeyPEM)) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:6,代码来源:test_import_RSA.py

示例11: testExportKey5

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def testExportKey5(self):
        key = RSA.construct([self.n, self.e])
        openssh_1 = key.exportKey("OpenSSH").split()
        openssh_2 = self.rsaPublicKeyOpenSSH.split()
        self.assertEqual(openssh_1[0], openssh_2[0])
        self.assertEqual(openssh_1[1], openssh_2[1]) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:8,代码来源:test_import_RSA.py

示例12: testExportKey8

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def testExportKey8(self):
        key = RSA.construct([self.n, self.e, self.d, self.p, self.q, self.pInv])
        pemKey = key.exportKey("PEM", pkcs=8)
        self.assertEqual(pemKey, b(self.rsaKeyPEM8)) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:6,代码来源:test_import_RSA.py

示例13: testExportKey9

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def testExportKey9(self):
        key = RSA.construct([self.n, self.e, self.d, self.p, self.q, self.pInv])
        self.assertRaises(ValueError, key.exportKey, "invalid-format") 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:5,代码来源:test_import_RSA.py

示例14: testExportKey10

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def testExportKey10(self):
        # Export and re-import the encrypted key. It must match.
        # PEM envelope, PKCS#1, old PEM encryption
        key = RSA.construct([self.n, self.e, self.d, self.p, self.q, self.pInv])
        outkey = key.exportKey('PEM', 'test')
        self.assertTrue(tostr(outkey).find('4,ENCRYPTED')!=-1)
        self.assertTrue(tostr(outkey).find('BEGIN RSA PRIVATE KEY')!=-1)
        inkey = RSA.importKey(outkey, 'test')
        self.assertEqual(key.n, inkey.n)
        self.assertEqual(key.e, inkey.e)
        self.assertEqual(key.d, inkey.d) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:13,代码来源:test_import_RSA.py

示例15: testExportKey11

# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import construct [as 别名]
def testExportKey11(self):
        # Export and re-import the encrypted key. It must match.
        # PEM envelope, PKCS#1, old PEM encryption
        key = RSA.construct([self.n, self.e, self.d, self.p, self.q, self.pInv])
        outkey = key.exportKey('PEM', 'test', pkcs=1)
        self.assertTrue(tostr(outkey).find('4,ENCRYPTED')!=-1)
        self.assertTrue(tostr(outkey).find('BEGIN RSA PRIVATE KEY')!=-1)
        inkey = RSA.importKey(outkey, 'test')
        self.assertEqual(key.n, inkey.n)
        self.assertEqual(key.e, inkey.e)
        self.assertEqual(key.d, inkey.d) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:13,代码来源:test_import_RSA.py


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