Refactored encrypt stream into a cipher.