凯撒加密
public class CaesarUtil {
private static int OFFSET = 6;
public static String encrypt(String str){
if(StringUtils.isEmpty(str)){
return null;
}
StringBuilder cipher = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
c += OFFSET ;
cipher.append(c);
}
return cipher.toString();
}
public static String decrypt (String str){
if(StringUtils.isEmpty(str)){
return null;
}
StringBuilder cipher = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
c -= OFFSET ;
cipher.append(c);
}
return cipher.toString();
}
}
es
在es创建索引的时候,设置mappring如下:
“_source":
{
"enabled":false
}
则往es中插入数据,只会存在倒排索引中,不会保存在es的原始文档中,则通过全文搜索查出来的数据并不包括该行的除id以外其他的字段属性,在写操作的时候,比如要写{id,123,name:"yangcai",age:23,school:"江西省南昌市华东交通大学"}
则把这行数据都插入到es和mongodb中去,在插入到mongodb中的时候,对scholl字段进行加密
在读操作的时候,加入对school字段进行全文搜索, 查询“华东”,则在es中查询出这条数据的主键id为123,然后在用主键id去mongodb中去查询,查询出的数据是加密的,需要用对象的解码算法进行解密