Пример #1
0
def decrypt(iv, key, ciphertext_bytes):
    """ Takes strings in and is expected to give strings out.
        All binary string conversion is internal only. """
    assert type(iv) == bytes
    assert type(key) == bytes
    assert type(ciphertext_bytes) == bytes

    codec = AES.new(bytestring(key), AES.MODE_CFB, bytestring(iv))
    return stdstring(codec.decrypt(ciphertext_bytes))
Пример #2
0
def decrypt(iv, key, ciphertext_bytes):
    """ Takes strings in and is expected to give strings out.
        All binary string conversion is internal only. """
    assert type(iv) == bytes
    assert type(key) == bytes
    assert type(ciphertext_bytes) == bytes

    codec = crypto.AES.new(bytestring(key), crypto.AES.MODE_CFB,
                           bytestring(iv))
    msg = stdstring(codec.decrypt(ciphertext_bytes))

    if msg[0] != '[' or msg[-1] != ']':
        return None, "Passphrase incorrect"
    return msg[1:-1], None
Пример #3
0
def encrypt_str(iv, key, plaintext):
    """ Takes strings in and is expected to give strings out.
        All binary string conversion is internal only.

        iv: 16 character standard string
        key: bytes array
        plaintext: standard string
    """
    assert type(iv) == bytes
    assert type(key) == bytes
    assert type(plaintext) == str

    codec = AES.new(bytestring(key), AES.MODE_CFB, iv)
    bindata = codec.encrypt(bytestring(plaintext))
    return bindata
Пример #4
0
def encrypt_str(iv, key, plaintext):
    """ Takes strings in and is expected to give strings out.
        All binary string conversion is internal only.

        iv: 16 character standard string
        key: bytes array
        plaintext: standard string
    """
    assert type(iv) == bytes
    assert type(key) == bytes
    assert type(plaintext) == str

    # Put fixes on string to be able to recognize successful decryption
    formatted = "[" + plaintext + "]"

    codec = crypto.AES.new(bytestring(key), crypto.AES.MODE_CFB, iv)
    bindata = codec.encrypt(bytestring(formatted))
    return bindata
Пример #5
0
def encode_prop(iv_bytes, key_salt_bytes, ciphertext_bytes):
    assert type(iv_bytes) == bytes
    assert len(iv_bytes) == IV_BLOCK_SIZE
    assert type(key_salt_bytes) == bytes
    assert len(key_salt_bytes) == SALT_BLOCK_SIZE
    assert type(ciphertext_bytes) == bytes

    tmp = iv_bytes + key_salt_bytes + ciphertext_bytes

    payload = base64.b64encode(bytestring(tmp))
    return "{" + stdstring(payload) + "}"
Пример #6
0
def make_key(salt, passphrase):
    dk = hashlib.pbkdf2_hmac('sha256', bytestring(passphrase),
                             bytestring(salt), 100000)
    return dk