Any way of encrypting the whole Entity?
albert0m opened this issue · 2 comments
albert0m commented
I have a class like this:
@PreferenceEntity(name = "MyPreferences")
public class MyPreferences {
@TypeConverter(converter = BaseGsonConverter.class)
protected Index MyClass;
}
I need to encrypt MyClass. How can I do that?
skydoves commented
Hello!
You can encrypt using BaseGsonConverter.class
or PreferenceFunction.
public class BaseGsonConverter<T> extends PreferenceTypeConverter<T> {
private final Gson gson;
/**
* default constructor will be called by PreferenceRoom
*/
public BaseGsonConverter(Class<T> clazz) {
super(clazz);
this.gson = new Gson();
}
@Override
public String convertObject(T object) {
return SecurityUtils.encrypt(gson.toJson(object)); // added encrypt logic
}
@Override
public T convertType(String string) {
return gson.fromJson(SecurityUtils.decrypt(string), clazz); // added decrpyt logic
}
}
But there are no way of encrypting the whole entity using annotation or function yet.
I will consider the best way to encrypt functions on the next version.
Thank you for your issue!
skydoves commented
@marconealberto
It's implemented encrypt & decrypt automatically using @EncryptEntity annotation at version 1.1.6
.
It is based on AES128 encryption. You can reference demo-project.
Thank you!