Пример #1
0
    def test_aes256cbc(self):
        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)
        self.assertEqual(plaintext, ctx.ciphering(enc))
Пример #2
0
    def test_aes256ctr(self):
        ciphername = "aes-256-ctr"
        print("\nTEST: AES-256-CTR")

        iv_hex = b"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"
        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)
        self.assertEqual(plaintext, ctx.ciphering(enc))
Пример #3
0
 def decryptfile(self, path):
     with open(path) as f1:
         tmpfile = mktemp(prefix='kina')
         with open(tmpfile, 'wb') as f2:
             iv = f1.read(Cipher.get_blocksize(CIPHERNAME))
             ctxsha256 = sha256()
             ctx = Cipher(self.key, iv, 0,
                          ciphername=CIPHERNAME)
             while True:
                 buff = f1.read(8192)
                 if len(buff) <= 0:
                     break
                 pbuff = ctx.update(buff)
                 ctxsha256.update(pbuff)
                 f2.write(pbuff)
             f2.write(ctx.final())
     move(tmpfile, path)
     return ctxsha256.hexdigest()
Пример #4
0
 def encryptfile(self, path):
     with open(path) as f1:
         tmpfile = mktemp(prefix='kina')
         with open(tmpfile, 'wb') as f2:
             iv = Cipher.gen_IV(CIPHERNAME)
             ctxsha256 = sha256()
             ctx = Cipher(self.key, iv, 1,
                          ciphername=CIPHERNAME)
             f2.write(iv)
             while True:
                 buff = f1.read(8192)
                 if len(buff) <= 0:
                     break
                 ctxsha256.update(buff)
                 f2.write(ctx.update(buff))
             f2.write(ctx.final())
     move(tmpfile, path)
     return ctxsha256.hexdigest()
Пример #5
0
    def test_aes256cbc(self):
        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)
        self.assertEqual(plaintext, ctx.ciphering(enc))
Пример #6
0
    def test_aes256ctr(self):
        ciphername = "aes-256-ctr"
        print("\nTEST: AES-256-CTR")

        iv_hex = b"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"
        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)
        self.assertEqual(plaintext, ctx.ciphering(enc))
Пример #7
0
# Boston, MA  02110-1301 USA

from pyelliptic import Cipher, ECC
from binascii import hexlify, unhexlify

print("TEST: AES-256-CTR")
ciphername = "aes-256-ctr"

iv_hex = b"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"
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: AES-256-CFB")
ciphername = "aes-256-cfb"
key_hex = b"603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"
key = unhexlify(key_hex)
iv_hex = b"000102030405060708090A0B0C0D0E0F"
iv = unhexlify(iv_hex)
plain_hex = b"6bc1bee22e409f96e93d7e117393172a"
plaintext = unhexlify(plain_hex)
Пример #8
0
# Boston, MA  02110-1301 USA

from pyelliptic import Cipher, ECC
from binascii import hexlify, unhexlify

print("TEST: AES-256-CTR")
ciphername = "aes-256-ctr"

iv_hex = b"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"
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: AES-256-CFB")
ciphername = "aes-256-cfb"
key_hex = b"603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"
key = unhexlify(key_hex)
iv_hex = b"000102030405060708090A0B0C0D0E0F"
iv = unhexlify(iv_hex)
plain_hex = b"6bc1bee22e409f96e93d7e117393172a"
plaintext = unhexlify(plain_hex)