Fix encrypt/decrypt and add json representation