MCPcopy Create free account
hub / github.com/Azure/azure-storage-python / RSAKeyWrapper

Class RSAKeyWrapper

tests/encryption_test_helper.py:56–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54
55
56class RSAKeyWrapper:
57 def __init__(self, kid='local:key2'):
58 self.private_key = generate_private_key(public_exponent=65537,
59 key_size=2048,
60 backend=default_backend())
61 self.public_key = self.private_key.public_key()
62 self.kid = kid
63
64 def wrap_key(self, key, algorithm='RSA'):
65 if algorithm == 'RSA':
66 return self.public_key.encrypt(key,
67 OAEP(
68 mgf=MGF1(algorithm=SHA1()),
69 algorithm=SHA1(),
70 label=None)
71 )
72 else:
73 raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM)
74
75 def unwrap_key(self, key, algorithm):
76 if algorithm == 'RSA':
77 return self.private_key.decrypt(key,
78 OAEP(
79 mgf=MGF1(algorithm=SHA1()),
80 algorithm=SHA1(),
81 label=None)
82 )
83 else:
84 raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM)
85
86 def get_key_wrap_algorithm(self):
87 return 'RSA'
88
89 def get_kid(self):
90 return self.kid

Calls

no outgoing calls

Tested by 2

test_get_blob_kek_RSAMethod · 0.72