def test_decrypt_invalidKey(self): key = keygen.generate() cyphertext, iv = aescypher.encrypt(self.plaintext, key) invalid_key = keygen.generate() while (invalid_key == key): invalid_key = keygen.generate() res = aescypher.decrypt(cyphertext, invalid_key, iv) self.assertNotEqual(self.plaintext, res)
def test_filename_write_read(self): key = keygen.generate() f = CryptoFile(testFile("data/hello_there.txt")) ofile = testFile("out/hello_there.out") f.write(ofile, key) f2 = CryptoFile(ofile, key) self.assertEqual((f2.path, f2.filename, f2.content), self.hello_content)
def test_generate_noparam(self): self.assertEqual(len(generate()), 32)
def test_generate_zero(self): with self.assertRaises(ValueError): generate(0)
def test_generate_256(self): self.assertEqual(len(generate(256)), 32)
def test_generate_192(self): self.assertEqual(len(generate(192)), 24)
def test_generate_128(self): self.assertEqual(len(generate(128)), 16)
def test_decrypt_char(self): key = keygen.generate() plaintext = "a".encode() cyphertext, iv = aescypher.encrypt(plaintext, key) res = aescypher.decrypt(cyphertext, key, iv) self.assertEqual(plaintext, res)
def test_decrypt_key192(self): key = keygen.generate(192) cyphertext, iv = aescypher.encrypt(self.plaintext, key) res = aescypher.decrypt(cyphertext, key, iv) self.assertEqual(self.plaintext, res)
def test_encrypt_notEqual(self): key = keygen.generate() cyphertext = aescypher.encrypt(self.plaintext, key)[0] self.assertNotEqual(self.plaintext, cyphertext)
def test_decrypt_givenIV(self): key = keygen.generate() iv = keygen.generate(128) cyphertext = aescypher.encrypt(self.plaintext, key, iv)[0] res = aescypher.decrypt(cyphertext, key, iv) self.assertEqual(self.plaintext, res)
def test_encrypt_blockSizeMismtch(self): key = keygen.generate() plaintext = "test".encode() cyphertext = aescypher.encrypt(plaintext, key)[0] self.assertNotEqual(plaintext, cyphertext)
def test_encrypt_givenIV(self): key = keygen.generate() iv = keygen.generate(128) ivOutput = aescypher.encrypt(self.plaintext, key, iv)[1] self.assertEqual(iv, ivOutput)