def change_key(self): if not self.loaded: self.load() old_key = self.get_encryption_key() new_key = AESEncryption.generate_key() for user in self.users: user_key = KeyPair(pub_data=user['public_key']) user['encrypted_key'] = user_key.encrypt(new_key, encode_payload=True) self.save(encryption_key=new_key)
def create(self, data=None): self.users = [] self.loaded = True keypair = self.get_private_keys()[0] encryption_key = AESEncryption.generate_key() self._add_user(self.user, keypair, encryption_key) payload = data or {} metdata = None self.save(payload, encryption_key=encryption_key)
def encrypt(self, message=None): print('Encrypting:', message) from pycloud.core.security import AESEncryption aes1 = AESEncryption() print('Using key:', aes1.get_key()) ciphertext = aes1.encrypt(message, encode=True) print('ciphertext:', ciphertext) aes2 = AESEncryption(aes1.get_key()) original = aes2.decrypt(ciphertext) print('{} == {}? {}'.format(message, original, original==message))