示例#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
示例#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
示例#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)
示例#4
0
文件: secret.py 项目: 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)