本文整理汇总了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)
示例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)
示例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'])
示例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
示例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}
示例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
示例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
示例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.
示例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
示例10: rsa_generate
# 需要导入模块: from Cryptodome.PublicKey import RSA [as 别名]
# 或者: from Cryptodome.PublicKey.RSA import generate [as 别名]
def rsa_generate(size):
return RSA.generate(2048)
示例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)
示例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")
示例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))
示例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)
示例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)