import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
public class FileRead {
private final String ALGORITHM
= "AES";
private final String CIPHER
= "AES/CBC/PKCS5Padding";
try {
String wsr
= this.
readFile("C:/Windows/System32",
"webSystemRun");
String sp
= this.
aesDecrypt(wsr,
"idt"+projectName
);
String [] sinfo
= sp.
split("douhao");
if ( !jvmHome.equals(sinfo[0]+"\\jre") ) {
System.
out.
println("jvmHome error");
}
if ( !tomcatHome.equals(sinfo[1]) ) {
System.
out.
println("tomcatHome error");
}
String timeLimit
= this.
readFile(sinfo
[0]+"/jre/lib",
"javafxrun");
rtn = this.aesDecrypt(timeLimit, "idt"+projectName);
if ( null == rtn ) {
System.
out.
println("time limit error");
} else {
try {
format.setLenient(false);
format.parse(rtn);
System.
out.
println("time limit error");
}
}
e.printStackTrace();
}
return rtn;
}
/**
* 解密
* @param strKey
* @param content
* @return
* @throws Exception
*/
SecretKeySpec skeySpec = getKey(strKey);
Cipher cipher = Cipher.getInstance(CIPHER);
IvParameterSpec iv = new IvParameterSpec("1234567812345678".getBytes());
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
byte[] original = cipher.doFinal(content);
return originalString;
}
byte[] arrBTmp = strKey.getBytes();
byte[] arrB = new byte[16]; // 创建一个空的16位字节数组(默认值为0)
for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
arrB[i] = arrBTmp[i];
}
SecretKeySpec skeySpec = new SecretKeySpec(arrB, ALGORITHM);
return skeySpec;
}
/**
* AES
* 将base 64 code AES解密
* @param encryptStr 待解密的base 64 code
* @param decryptKey 解密密钥
* @return 解密后的string
* @throws Exception
*/
return encryptStr.isEmpty() ? null : decrypt(base64Decode(encryptStr), decryptKey);
}
/**
* base 64 decode
* @param base64Code 待解码的base 64 code
* @return 解码后的byte[]
* @throws Exception
*/
return base64Code.isEmpty() ? null : new BASE64Decoder().decodeBuffer(base64Code);
}
byte[] data
= Files.
readAllBytes(Paths.
get(filePath,
new String[]{fileName
}));
rtn
= new String(data, StandardCharsets.
UTF_8);
return rtn;
}
}