-
Notifications
You must be signed in to change notification settings - Fork 347
自定义加密算法
尹吉欢 edited this page Jan 12, 2019
·
1 revision
内置了AES加密算法对数据进行加解密操作,同时用户可以自定义算法来代替内置的算法。
自定义算法需要实现EncryptAlgorithm接口:
/**
* 自定义RSA算法
*
* @author yinjihuan
*
* @date 2019-01-12
*
* @about http://cxytiandi.com/about
*
*/
public class RsaEncryptAlgorithm implements EncryptAlgorithm {
public String encrypt(String content, String encryptKey) throws Exception {
return RSAUtils.encryptByPublicKey(content);
}
public String decrypt(String encryptStr, String decryptKey) throws Exception {
return RSAUtils.decryptByPrivateKey(encryptStr);
}
}
注册Filter的时候指定算法:
EncryptionConfig config = new EncryptionConfig();
registration.setFilter(new EncryptionFilter(config, new RsaEncryptAlgorithm()));