Refactored encryption header logic.