You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/03/13 04:44:57 UTC
[GitHub] [incubator-shardingsphere] Jaskey commented on issue #4741: How to
implement a user-define encryptors
Jaskey commented on issue #4741: How to implement a user-define encryptors
URL: https://github.com/apache/incubator-shardingsphere/issues/4741#issuecomment-598545620
After Reading some source code, Solution found!
1. Given your Encryptor which implements
```
public class TestShardingEncryptor implements ShardingEncryptor {
private Properties properties = new Properties();
@Override
public String getType() {
return "TEST";
}
@Override
public void init() {
log.info("==============init ");
}
@Override
public String encrypt(final Object plaintext) {
return "TEST-"+String.valueOf(plaintext);
}
@Override
public Object decrypt(final String ciphertext) {
return ciphertext.replaceAll("TEST-","");
}
}
```
2. Create a spi file in your resouce folder
.....src\main\resources\META-INF\services\org.apache.shardingsphere.spi.encrypt.ShardingEncryptor
And write your class name in the file like
mytest.sharding.TestShardingEncryptor
3. At last, every ShardingEncryptor has a type value which return from `getType` method(in my case, that is "TEST") ,
Just use your Type when configuring EncryptorRuleConfiguration, in Java Config case, that is
EncryptorRuleConfiguration encryptorConfig = new EncryptorRuleConfiguration("TEST", props);
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services