Ejemplo n.º 1
0
 def test_ecies(self):
     print("\nTEST: ECIES")
     alice = ECC()
     plaintext = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     ciphertext = alice.encrypt(plaintext, alice.get_pubkey())
     print(hexlify(ciphertext))
     self.assertEqual(plaintext, alice.decrypt(ciphertext))
Ejemplo n.º 2
0
 def test_ecies(self):
     print("\nTEST: ECIES")
     alice = ECC()
     plaintext = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     ciphertext = alice.encrypt(plaintext, alice.get_pubkey())
     print(hexlify(ciphertext))
     self.assertEqual(plaintext, alice.decrypt(ciphertext))
Ejemplo n.º 3
0
ciphername = "aes-256-cbc"
iv_hex = b"000102030405060708090A0B0C0D0E0F"
iv = unhexlify(iv_hex)
key_hex = b"603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"
key = unhexlify(key_hex)
plain_hex = b"6bc1bee22e409f96e93d7e117393172a"
plaintext = unhexlify(plain_hex)

ctx = Cipher(key, iv, 1, ciphername=ciphername)
enc = ctx.ciphering(plaintext)
print(hexlify(enc))

ctx = Cipher(key, iv, 0, ciphername=ciphername)
assert ctx.ciphering(enc) == plaintext


print("\nTEST: ECIES")
alice = ECC()
plaintext = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
ciphertext = ECC.encrypt(plaintext, alice.get_pubkey())
print(hexlify(ciphertext))
assert alice.decrypt(ciphertext) == plaintext


print("\nTEST: ECIES/RC4")
alice = ECC()
plaintext = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
ciphertext = ECC.encrypt(plaintext, alice.get_pubkey(), ciphername="rc4")
print(hexlify(ciphertext))
assert alice.decrypt(ciphertext, ciphername="rc4") == plaintext
Ejemplo n.º 4
0
print("\nTEST: AES-256-CBC")
ciphername = "aes-256-cbc"
iv_hex = b"000102030405060708090A0B0C0D0E0F"
iv = unhexlify(iv_hex)
key_hex = b"603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"
key = unhexlify(key_hex)
plain_hex = b"6bc1bee22e409f96e93d7e117393172a"
plaintext = unhexlify(plain_hex)

ctx = Cipher(key, iv, 1, ciphername=ciphername)
enc = ctx.ciphering(plaintext)
print(hexlify(enc))

ctx = Cipher(key, iv, 0, ciphername=ciphername)
assert ctx.ciphering(enc) == plaintext

print("\nTEST: ECIES")
alice = ECC()
plaintext = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
ciphertext = ECC.encrypt(plaintext, alice.get_pubkey())
print(hexlify(ciphertext))
assert alice.decrypt(ciphertext) == plaintext

print("\nTEST: ECIES/RC4")
alice = ECC()
plaintext = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
ciphertext = ECC.encrypt(plaintext, alice.get_pubkey(), ciphername="rc4")
print(hexlify(ciphertext))
assert alice.decrypt(ciphertext, ciphername="rc4") == plaintext