當前位置: 首頁>>代碼示例>>Python>>正文


Python RSA.generate方法代碼示例

本文整理匯總了Python中Cryptodome.PublicKey.RSA.generate方法的典型用法代碼示例。如果您正苦於以下問題:Python RSA.generate方法的具體用法?Python RSA.generate怎麽用?Python RSA.generate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cryptodome.PublicKey.RSA的用法示例。


在下文中一共展示了RSA.generate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: runTest

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def runTest(self):

        key = RSA.generate(1024)
        signer = pkcs1_15.new(key)
        hash_names = ("MD2", "MD4", "MD5", "RIPEMD160", "SHA1",
                      "SHA224", "SHA256", "SHA384", "SHA512",
                      "SHA3_224", "SHA3_256", "SHA3_384", "SHA3_512")

        for name in hash_names:
            hashed = load_hash_by_name(name).new(b("Test"))
            signer.sign(hashed)

        from Cryptodome.Hash import BLAKE2b, BLAKE2s
        for hash_size in (20, 32, 48, 64):
            hashed_b = BLAKE2b.new(digest_bytes=hash_size, data=b("Test"))
            signer.sign(hashed_b)
        for hash_size in (16, 20, 28, 32):
            hashed_s = BLAKE2s.new(digest_bytes=hash_size, data=b("Test"))
            signer.sign(hashed_s) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:21,代碼來源:test_pkcs1_15.py

示例2: runTest

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def runTest(self):

        key = RSA.generate(1280)
        signer = pss.new(key)
        hash_names = ("MD2", "MD4", "MD5", "RIPEMD160", "SHA1",
                      "SHA224", "SHA256", "SHA384", "SHA512",
                      "SHA3_224", "SHA3_256", "SHA3_384", "SHA3_512")

        for name in hash_names:
            hashed = load_hash_by_name(name).new(b("Test"))
            signer.sign(hashed)

        from Cryptodome.Hash import BLAKE2b, BLAKE2s
        for hash_size in (20, 32, 48, 64):
            hashed_b = BLAKE2b.new(digest_bytes=hash_size, data=b("Test"))
            signer.sign(hashed_b)
        for hash_size in (16, 20, 28, 32):
            hashed_s = BLAKE2s.new(digest_bytes=hash_size, data=b("Test"))
            signer.sign(hashed_s) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:21,代碼來源:test_pss.py

示例3: test_kwargs

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def test_kwargs(self):
        """
        This function tests the kwargs for the MslClient initialization
        to make sure that they are properly set
        """

        esn = 'NFCDIE-02-TDP0LTTSNSC3EHLL71FRYFOEEAZYQ3'
        drm_system = 'playready'
        profiles = ['ddplus-5.1-dash']
        keypair = RSA.generate(2048)
        message_id = 123456789
        languages = ['de-DE']

        client = pymsl.MslClient(
            {'scheme': 'EMAIL_PASSWORD'},
            esn=esn,
            drm_system=drm_system,
            profiles=profiles,
            keypair=keypair,
            message_id=message_id,
            languages=languages
        )

        self.assertEqual(esn, client.msl_session['esn'])
        self.assertEqual(drm_system, client.msl_session['drm_system'])
        self.assertEqual(profiles, client.msl_session['profiles'])
        self.assertEqual(keypair, client.msl_session['keypair'])
        self.assertEqual(message_id, client.msl_session['message_id'])
        self.assertEqual(languages, client.msl_session['languages']) 
開發者ID:truedread,項目名稱:pymsl,代碼行數:31,代碼來源:tests.py

示例4: load_crypto_session

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def load_crypto_session(self, msl_data=None):
        try:
            self.encryption_key = base64.standard_b64decode(
                msl_data['encryption_key'])
            self.sign_key = base64.standard_b64decode(
                msl_data['sign_key'])
            if not self.encryption_key or not self.sign_key:
                raise MSLError('Missing encryption_key or sign_key')
            self.rsa_key = RSA.importKey(
                base64.standard_b64decode(msl_data['rsa_key']))
        except Exception:  # pylint: disable=broad-except
            common.debug('Generating new RSA keys')
            self.rsa_key = RSA.generate(2048)
            self.encryption_key = None
            self.sign_key = None 
開發者ID:CastagnaIT,項目名稱:plugin.video.netflix,代碼行數:17,代碼來源:default_crypto.py

示例5: __generate_ssh_key_pair

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def __generate_ssh_key_pair(self):
        key = RSA.generate(2048)
        priv_key = key.exportKey("PEM")
        pub_key = key.publickey().exportKey("OpenSSH")
        return {"pub_key": pub_key, "priv_key": priv_key} 
開發者ID:Azure,項目名稱:aztk,代碼行數:7,代碼來源:models.py

示例6: generate_user_on_node

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def generate_user_on_node(base_client, pool_id, node_id):
    generated_username = secure_utils.generate_random_string()
    ssh_key = RSA.generate(2048)
    ssh_pub_key = ssh_key.publickey().exportKey("OpenSSH").decode("utf-8")
    base_client.create_user_on_node(pool_id, node_id, generated_username, ssh_pub_key)
    return generated_username, ssh_key 
開發者ID:Azure,項目名稱:aztk,代碼行數:8,代碼來源:generate_user_on_node.py

示例7: generate_user_on_cluster

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def generate_user_on_cluster(base_operations, id, nodes):
    generated_username = secure_utils.generate_random_string()
    ssh_key = RSA.generate(2048)
    ssh_pub_key = ssh_key.publickey().exportKey("OpenSSH").decode("utf-8")
    with concurrent.futures.ThreadPoolExecutor() as executor:
        futures = {
            executor.submit(base_operations.create_user_on_node, id, node.id, generated_username, ssh_pub_key): node
            for node in nodes
        }
        concurrent.futures.wait(futures)

    return generated_username, ssh_key 
開發者ID:Azure,項目名稱:aztk,代碼行數:14,代碼來源:generate_user_on_cluster.py

示例8: generate_rsa_key

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def generate_rsa_key(key_size):
    """
    Creates a key_size-bit RSA key and returns private key as string
    """
    rsa_key = RSA.generate(key_size)
    return rsa_key.exportKey().decode("utf-8")


# Constants ###################################################################

# The names of Ansible variables that should be set to independent random keys. 
開發者ID:open-craft,項目名稱:opencraft,代碼行數:13,代碼來源:secret_keys.py

示例9: generate_key

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def generate_key(self, rsa_bit=1024):
        random_generator = Random.new().read
        rsa = RSA.generate(rsa_bit, random_generator)
        self.e = rsa.e
        self.d = rsa.d
        self.n = rsa.n 
開發者ID:FederatedAI,項目名稱:FATE,代碼行數:8,代碼來源:encrypt.py

示例10: rsa_generate

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def rsa_generate(size):
    return RSA.generate(2048) 
開發者ID:keylime,項目名稱:keylime,代碼行數:4,代碼來源:cryptodome.py

示例11: substitute_record_params

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def substitute_record_params(params, email, record_data):
        # type: (KeeperParams, str, dict) -> None

        values = {
            'user_email': email,
            'generate_password': generate(length=32)
        }
        for u in params.enterprise['users']:
            if u['username'].lower() == email.lower():
                values['user_name'] = u['data'].get('displayname') or ''
                break

        EnterprisePushCommand.enumerate_and_substitute_dict_fields(record_data, values) 
開發者ID:Keeper-Security,項目名稱:Commander,代碼行數:15,代碼來源:enterprise.py

示例12: signing_key

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def signing_key(self):
        return RSAKey(key=RSA.generate(2048), alg="RS256") 
開發者ID:IdentityPython,項目名稱:SATOSA,代碼行數:4,代碼來源:test_openid_connect.py

示例13: handle

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def handle(self, *args, **options):
        try:
            key = RSA.generate(2048)
            rsakey = RSAKey(key=key.exportKey('PEM').decode('utf8'))
            rsakey.save()
            self.stdout.write(u'RSA key successfully created with kid: {0}'.format(rsakey.kid))
        except Exception as e:
            self.stdout.write('Something goes wrong: {0}'.format(e)) 
開發者ID:juanifioren,項目名稱:django-oidc-provider,代碼行數:10,代碼來源:creatersakey.py

示例14: save

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def save(self):
        scripts = self._generate_vagrantfile()
        key = RSA.generate(2048)
        private_key = key.exportKey('PEM')
        public_key = key.publickey().exportKey('OpenSSH')

        os.makedirs(self._dep_dir, exist_ok=False)
        metadata_file = os.path.join(self._dep_dir, Constant.METADATA_FILENAME)
        with open(metadata_file, 'w') as file:
            json.dump({
                'id': self.dep_id,
                'settings': self.settings
            }, file, cls=SettingsEncoder)

        for filename, script in scripts.items():
            full_path = os.path.join(self._dep_dir, filename)
            with open(full_path, 'w') as file:
                file.write(script)

        # generate ssh key pair
        keys_dir = os.path.join(self._dep_dir, 'keys')
        os.makedirs(keys_dir)

        with open(os.path.join(keys_dir, Constant.SSH_KEY_NAME), 'w') as file:
            file.write(private_key.decode('utf-8'))
        os.chmod(os.path.join(keys_dir, Constant.SSH_KEY_NAME), 0o600)

        with open(os.path.join(keys_dir, str(Constant.SSH_KEY_NAME + '.pub')), 'w') as file:
            file.write(str(public_key.decode('utf-8') + " sesdev\n"))
        os.chmod(os.path.join(keys_dir, str(Constant.SSH_KEY_NAME + '.pub')), 0o600)

        # bin dir with helper scripts
        bin_dir = os.path.join(self._dep_dir, 'bin')
        os.makedirs(bin_dir) 
開發者ID:SUSE,項目名稱:sesdev,代碼行數:36,代碼來源:deployment.py

示例15: test_can_sign

# 需要導入模塊: from Cryptodome.PublicKey import RSA [as 別名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 別名]
def test_can_sign(self):
        test_public_key = RSA.generate(1024).publickey()
        verifier = pkcs1_15.new(test_public_key)
        self.assertEqual(verifier.can_sign(), False) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:6,代碼來源:test_pkcs1_15.py


注:本文中的Cryptodome.PublicKey.RSA.generate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。