建立properties文件
public static void init(){
Properties properties = new Properties();
//加载properties文件
InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("omssn.properties");
InputStreamReader inputStreamReader= null;
try {
inputStreamReader = new InputStreamReader(resourceAsStream,"UTF-8");
//load方法能够加载属性文件中的文件的性质,他只能将文件加载到Properties对象中,在加载属性文件时,会将文件中的内容转换成键值对,方便后续通过键来获取
properties.load(inputStreamReader);
String mode = properties.getProperty("Mode");
System.out.println("properties文件中的数据mode:" + mode);
} catch (Exception e) {
e.printStackTrace();
}
}
main方法
public static void main(String[] args) {
init();
String encryption = encryption("hello workd 你好=我");
// 加密: 7e6ac9def677931c7b6e16b0fa015ae0111d81ac915a4bc08ed333e7011a75c0
System.out.println("加密: " + encryption);
String decryption = decryption(encryption);
// 解密: oSE7x4q0Q-TXfGFESvdSoT9wqhq0
System.out.println("解密: " + decryption);
}
输出控制台