Ejemplo n.º 1
0
 def decrypt_str(self, content, key, salt):
     # content contains the gcm tag and salt_explicit in plaintext
     salt_explicit, gcm_tag = struct.unpack_from('!q16s', content)
     cipher = Cipher(algorithms.AES(key),
                     modes.GCM(initialization_vector=self._bulid_iv(salt, salt_explicit), tag=gcm_tag),
                     backend=default_backend()
                     ).decryptor()
     return cipher.update(content[24:]) + cipher.finalize()
Ejemplo n.º 2
0
 def encrypt_str(self, content, key, salt, salt_explicit):
     # return the encrypted content prepended with the
     # gcm tag and salt_explicit
     cipher = Cipher(algorithms.AES(key),
                     modes.GCM(initialization_vector=self._bulid_iv(salt, salt_explicit)),
                     backend=default_backend()
                     ).encryptor()
     ciphertext = cipher.update(content) + cipher.finalize()
     return struct.pack('!q16s', salt_explicit, cipher.tag) + ciphertext
Ejemplo n.º 3
0
 def decrypt_str(self, content, key, salt):
     # content contains the gcm tag and salt_explicit in plaintext
     salt_explicit, gcm_tag = struct.unpack_from('!q16s', content)
     cipher = Cipher(algorithms.AES(key),
                     modes.GCM(initialization_vector=self._bulid_iv(
                         salt, salt_explicit),
                               tag=gcm_tag),
                     backend=default_backend()).decryptor()
     return cipher.update(content[24:]) + cipher.finalize()
Ejemplo n.º 4
0
 def encrypt_str(self, content, key, salt, salt_explicit):
     # return the encrypted content prepended with the
     # gcm tag and salt_explicit
     cipher = Cipher(algorithms.AES(key),
                     modes.GCM(initialization_vector=self._bulid_iv(salt, salt_explicit)),
                     backend=default_backend()
                     ).encryptor()
     ciphertext = cipher.update(content) + cipher.finalize()
     return struct.pack('!q16s', salt_explicit, cipher.tag) + ciphertext