def enc_file(filepath): key = SIV.generate_key() siv = SIV(key) nonce = os.urandom(16) with open(filepath, 'r') as myfile: data = myfile.read().encode() ciphertext = siv.seal(data, [nonce]) return (key, nonce, nonce + ciphertext) #returning ciphertext with the nonce (first 16 bytes) return None
def encryption_machine(msg): encrypt = [] key = SIV.generate_key() siv = SIV(key) nonce = os.urandom(16) # create a random nonce ciphertext = siv.seal(msg, [nonce]) # msg is in byte encrypt.append(ciphertext) encrypt.append(nonce) encrypt.append(key) return encrypt # we create a list with the nonce, the key and the ciphertext to be able to decrypt it later
def _gen_key(): """ Generate key, initialize SIV object, and return relevant data """ k = SIV.generate_key() siv = SIV(k) ret = { "k": k, "siv": siv, "nonce": os.urandom(16) } return ret
def test_generate_key(self): """Ensure we can generate random keys with the right default size""" key = SIV.generate_key() self.assertEqual(len(key), 32)