示例#1
0
def test_reset_cipher():
    c = ciphers.Cipher(b'AES', u'CBC')
    c.key = '0123456789ABCDEF'
    c.iv = '0123456789ABCDEF'
    c.reset()
    assert c.key == b'0123456789ABCDEF'
    assert c.iv == None
示例#2
0
def test_get_info():
    """
    Let's test getting keylen or blocksize from the cipher
    """
    c = ciphers.Cipher(b'AES', u'CBC')
    assert c.keylen == 16
    assert c.blocksize == 16
示例#3
0
def test_init():
    """
    Let's test the initialisation of a cipher
    """
    c = ciphers.Cipher(b'AES', u'CBC')
    assert c.algo == b'AES'
    assert c.mode == 'CBC'
示例#4
0
def test_encrypt_decrypt():
    c = ciphers.Cipher(b'AES', u'CBC')
    c.key = '0123456789ABCDEF'
    c.iv = '0123456789ABCDEF'
    encrypt = c.encrypt(b'0123456789ABCDEF')
    c.reset()
    c.iv = '0123456789ABCDEF'
    assert c.decrypt(encrypt) == b'0123456789ABCDEF'
示例#5
0
def test_set_key_iv():
    """
    Let's try to set a key and an iv on a cipher.
    """
    c = ciphers.Cipher(b'AES', u'CBC')
    c.key = '0123456789ABCDEF'
    assert c.key == b'0123456789ABCDEF'
    c.iv = '0123456789ABCDEF'
    assert c.iv == b'0123456789ABCDEF'
示例#6
0
#!/usr/bin/env python

import os, sys, binascii

from pygcrypt import ciphers

c = ciphers.Cipher(b'AES', u'CBC')
#print dir(c)

org = b'0123456789ABCDEF'
print("original:", org, binascii.hexlify(org))

c.key = '0123456789ABCDEF'
c.iv = '0123456789ABCDEF'
encrypted = c.encrypt(org)
print("encrypted:", binascii.hexlify(encrypted))

cc = ciphers.Cipher(b'AES', u'CBC')
#c.reset()
cc.key = '0123456789ABCDEF'
cc.iv = '0123456789ABCDEF'

decrypted = cc.decrypt(encrypted)

print("decrypted:", binascii.hexlify(decrypted), decrypted)