描述:
同一个文件我转成字符串之后传的MD5函数中计算值校验数据,在本地windows上正常通过校验,在linux上校验未通过。
排查:
打印日志文件发现两个系统的MD5值不一致
原因:贴出转换代码
//读取js返回String
public static String js2string(String path){
StringBuffer out
= new StringBuffer();
try{
InputStreamReader inreader = new InputStreamReader(classLoader.getResourceAsStream(path));
BufferedReader br = new BufferedReader(inreader);
String str = null;
while ((str = br.readLine()) != null) {
out.append(System.lineSeparator() + str);
}
br.close();
inreader.close();
}catch (Exception e){
e.printStackTrace();
}
return out.toString();
}
症结所在:注意System.lineSeparator()方法 On UNIX systems, it returns "n"; on Microsoft Windows systems it returns "rn"。
处理方案:
换行不再使用System.lineSeparator()方法,而是写死 "rn",亲测有效
最后
以上就是强健钢笔最近收集整理的关于LINUX/UNIX 和WINDOWS计算的MD5值不一致的全部内容,更多相关LINUX/UNIX内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复