refactor crypto handler.

Signed-off-by: Yi Ling <e3.gemini@qq.com>