Refactors cipher logic into helper class

Refactor a bit of logic into a helper class to
make way to add a new API.

Test Plan:
Both integration and unit tests pass.