當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。