def sign(self, message, privKeyPath, password): if type(message) is str: message = message.encode('utf-8') key = RSA.importKey(BasicFunctions.binaryReader(privKeyPath), password) Hash = SHA3_512.new(message) signature = pss.new(key).sign(Hash) return signature
def _publicKey(self, path, databasePath): if os.path.exists(path): key = BasicFunctions.binaryReader(path) else: raise PathDoesNotExist(self.username) importpath = os.path.join(databasePath, '{}.pem'.format(self.username)) BasicFunctions.binaryWriter(importpath, key) return importpath
def verify(self, message, pubKeyPath, signature): if type(message) is str: message = message.encode('utf-8') key = RSA.importKey(BasicFunctions.binaryReader(pubKeyPath)) Hash = SHA3_512.new(message) verifier = pss.new(key) try: verifier.verify(Hash, signature) except (ValueError, TypeError): return False return True
def decrypt(self, message, privKeyPath, password): key = RSA.importKey(BasicFunctions.binaryReader(privKeyPath), password) cipher = PKCS1_OAEP.new(key) plaintext = cipher.decrypt(message) return plaintext
def encrypt(self, message, pubKeyPath): key = RSA.importKey(BasicFunctions.binaryReader(pubKeyPath)) cipher = PKCS1_OAEP.new(key) ciphertext = cipher.encrypt(message) return ciphertext