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
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)
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)