Add encryption class
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
from pathlib import Path
|
||||
from os import walk, chmod
|
||||
from os import chmod
|
||||
from Crypto.PublicKey import RSA
|
||||
|
||||
class ssh_key:
|
||||
class SshKey:
|
||||
"""
|
||||
Object class for a ssh key
|
||||
"""
|
||||
@@ -38,25 +38,23 @@ class Collection:
|
||||
public class to generate a ssh key
|
||||
"""
|
||||
key = RSA.generate(2048)
|
||||
sshKey = ssh_key(name=name, key_type=key_type, private=key.exportKey('PEM'), public=key.publickey().exportKey('OpenSSH'))
|
||||
self.save_ssh_key(sshKey=sshKey)
|
||||
my_ssh_key = SshKey(name=name, key_type=key_type, private=key.exportKey('PEM'), public=key.publickey().exportKey('OpenSSH'))
|
||||
self.save_ssh_key(my_ssh_key=my_ssh_key)
|
||||
|
||||
def save_ssh_key(self, sshKey: ssh_key):
|
||||
def save_ssh_key(self, my_ssh_key: SshKey):
|
||||
"""
|
||||
Function to save the sshkey
|
||||
Function to save the ssh key
|
||||
"""
|
||||
key_file_path = self.collection_path.joinpath(sshKey.get_name())
|
||||
key_file_path = self.collection_path.joinpath(my_ssh_key.get_name())
|
||||
## Info File
|
||||
with open(f"{key_file_path}.txt", "w+", encoding="utf-8") as info_file:
|
||||
info_file.write(f"name: {sshKey.get_name()}\nKey_type: {sshKey.get_type()}")
|
||||
info_file.write(f"name: {my_ssh_key.get_name()}\nKey_type: {my_ssh_key.get_type()}")
|
||||
|
||||
## Private Key
|
||||
with open(key_file_path, "wb") as private_file:
|
||||
private_file.write(sshKey.get_private())
|
||||
private_file.write(my_ssh_key.get_private())
|
||||
chmod(key_file_path, 0o600)
|
||||
|
||||
## Public Key
|
||||
with open(f"{key_file_path}.pub", "wb") as public_file:
|
||||
public_file.write(sshKey.get_public())
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public_file.write(my_ssh_key.get_public())
|
||||
|
||||
Reference in New Issue
Block a user