refactor entity type as enum and CryptoHandler

let the code seem to be more readable.