Esempio n. 1
0
def encode_blob(plaintext):
    assert isinstance(plaintext, bytes), 'Plaintext should be bytes'
    compressed = zlib.compress(plaintext)
    encryption_oracle = get_encryption_oracle('BLOCK_ENCRYPTION_KEY')
    ciphertext, scheme = encryption_oracle.encrypt(compressed)
    header = _pack_header(scheme)
    return header + ciphertext
Esempio n. 2
0
def encode_blob(plaintext):
    assert isinstance(plaintext, bytes), 'Plaintext should be bytes'
    compressed = zlib.compress(plaintext)
    encryption_oracle = get_encryption_oracle('BLOCK_ENCRYPTION_KEY')
    ciphertext, scheme = encryption_oracle.encrypt(compressed)
    header = _pack_header(scheme)
    return header + ciphertext
Esempio n. 3
0
    def secret(self, plaintext):
        if isinstance(plaintext, unicode):
            plaintext = plaintext.encode("utf8")
        if not isinstance(plaintext, bytes):
            raise TypeError("Invalid secret")

        with get_encryption_oracle("SECRET_ENCRYPTION_KEY") as e_oracle:
            self._secret, self.encryption_scheme = e_oracle.encrypt(plaintext)
Esempio n. 4
0
File: secret.py Progetto: wmv/inbox
    def secret(self, plaintext):
        """
        The secret must be a byte sequence.
        The type must be specified as 'password'/'token'.

        """
        if not isinstance(plaintext, bytes):
            raise TypeError('Invalid secret')

        with get_encryption_oracle('SECRET_ENCRYPTION_KEY') as e_oracle:
            self._secret, self.encryption_scheme = e_oracle.encrypt(plaintext)