示例#1
0
 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
示例#2
0
 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
示例#3
0
 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
示例#4
0
 def decrypt(self, message, privKeyPath, password):
     key = RSA.importKey(BasicFunctions.binaryReader(privKeyPath), password)
     cipher = PKCS1_OAEP.new(key)
     plaintext = cipher.decrypt(message)
     return plaintext
示例#5
0
 def encrypt(self, message, pubKeyPath):
     key = RSA.importKey(BasicFunctions.binaryReader(pubKeyPath))
     cipher = PKCS1_OAEP.new(key)
     ciphertext = cipher.encrypt(message)
     return ciphertext