|
@@ -9,15 +9,44 @@ import rsa
|
|
|
#k.close()
|
|
#k.close()
|
|
|
|
|
|
|
|
# create the pub & private keys for the parties
|
|
# create the pub & private keys for the parties
|
|
|
|
|
+
|
|
|
|
|
+from cryptography.hazmat.backends import default_backend
|
|
|
|
|
+from cryptography.hazmat.primitives.asymmetric import rsa
|
|
|
|
|
+from cryptography.hazmat.primitives import serialization
|
|
|
|
|
+
|
|
|
def make_keys(company):
|
|
def make_keys(company):
|
|
|
- (pubkey,privkey)=rsa.newkeys(2048)
|
|
|
|
|
|
|
+ #(pubkey,privkey)=rsa.newkeys(2048)
|
|
|
|
|
+ private_key = rsa.generate_private_key(
|
|
|
|
|
+ public_exponent=65537,
|
|
|
|
|
+ key_size=2048,
|
|
|
|
|
+ backend=default_backend()
|
|
|
|
|
+ )
|
|
|
|
|
+ public_key = private_key.public_key()
|
|
|
|
|
+
|
|
|
|
|
+ pem = private_key.private_bytes(
|
|
|
|
|
+ encoding=serialization.Encoding.PEM,
|
|
|
|
|
+ format=serialization.PrivateFormat.PKCS8,
|
|
|
|
|
+ encryption_algorithm=serialization.NoEncryption()
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
|
|
+ with open('companies\\' + company + '_publickey.key','wb') as f:
|
|
|
|
|
+ f.write(pem)
|
|
|
|
|
+
|
|
|
|
|
+ pem = private_key.private_bytes(
|
|
|
|
|
+ encoding=serialization.Encoding.PEM,
|
|
|
|
|
+ format=serialization.PrivateFormat.PKCS8,
|
|
|
|
|
+ encryption_algorithm=serialization.NoEncryption()
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ with open('companies\\' + company + '_privatekey.key','wb') as f:
|
|
|
|
|
+ f.write(pem)
|
|
|
|
|
+
|
|
|
#write the public key to a file
|
|
#write the public key to a file
|
|
|
- pukey = open('companies\\' + company + '_publickey.key','wb')
|
|
|
|
|
- pukey.write(pubkey.save_pkcs1('PEM'))
|
|
|
|
|
- pukey.close()
|
|
|
|
|
-
|
|
|
|
|
- # write the private key to a file
|
|
|
|
|
- prkey = open('companies\\' + company + '_privatekey.key','wb')
|
|
|
|
|
- prkey.write(privkey.save_pkcs1('PEM'))
|
|
|
|
|
- prkey.close()
|
|
|
|
|
|
|
+ # pukey = open('companies\\' + company + '_publickey.key','wb')
|
|
|
|
|
+ # pukey.write(pubkey.save_pkcs1('PEM'))
|
|
|
|
|
+ # pukey.close()
|
|
|
|
|
+
|
|
|
|
|
+ # # write the private key to a file
|
|
|
|
|
+ # prkey = open('companies\\' + company + '_privatekey.key','wb')
|
|
|
|
|
+ # prkey.write(privkey.save_pkcs1('PEM'))
|
|
|
|
|
+ # prkey.close()
|