Read the file and use AES to decrypt it. If unsuccessful, exit the Java virtual machine

From , 3 Years ago, written in Java, viewed 220 times.
URL https://pastebin.vip/view/9d268236
  1. import java.nio.charset.StandardCharsets;
  2. import java.nio.file.Files;
  3. import java.nio.file.Paths;
  4. import java.text.SimpleDateFormat;
  5.  
  6. import javax.crypto.Cipher;
  7. import javax.crypto.spec.IvParameterSpec;
  8. import javax.crypto.spec.SecretKeySpec;
  9.  
  10. import sun.misc.BASE64Decoder;
  11.  
  12. public class FileRead {
  13.  
  14.         private final String ALGORITHM = "AES";
  15.         private final String CIPHER = "AES/CBC/PKCS5Padding";
  16.        
  17.         public String fileRead(String projectName) throws Exception {
  18.                 String rtn = "fail";
  19.                 try {
  20.                         String jvmHome = System.getProperty("java.home");
  21.                         String tomcatHome = System.getProperty("catalina.home");
  22.                         String wsr = this.readFile("C:/Windows/System32", "webSystemRun");
  23.                         String sp = this.aesDecrypt(wsr, "idt"+projectName);
  24.                         String [] sinfo = sp.split("douhao");
  25.                         if ( !jvmHome.equals(sinfo[0]+"\\jre") ) {
  26.                                 System.out.println("jvmHome error");
  27.                                 System.exit(1);
  28.                         }
  29.                         if ( !tomcatHome.equals(sinfo[1]) ) {
  30.                                 System.out.println("tomcatHome error");
  31.                                 System.exit(1);
  32.                         }
  33.                         String timeLimit = this.readFile(sinfo[0]+"/jre/lib", "javafxrun");
  34.                         rtn = this.aesDecrypt(timeLimit, "idt"+projectName);
  35.                         if ( null == rtn ) {
  36.                                 System.out.println("time limit error");
  37.                                 System.exit(1);
  38.                         } else {
  39.                                 try {
  40.                                 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  41.                                 format.setLenient(false);
  42.                                 format.parse(rtn);
  43.                                 } catch ( Exception e ) {
  44.                                         System.out.println("time limit error");
  45.                                         System.exit(1);
  46.                                 }
  47.                         }
  48.                 } catch ( Exception e ) {
  49.                         e.printStackTrace();
  50.                         System.exit(1);
  51.                 }
  52.                 return rtn;
  53.         }
  54.  
  55.         /**
  56.         * 解密
  57.         * @param strKey
  58.         * @param content
  59.         * @return
  60.         * @throws Exception
  61.         */
  62.         private String decrypt(byte[] content,String strKey ) throws Exception {
  63.                 SecretKeySpec skeySpec = getKey(strKey);
  64.                 Cipher cipher = Cipher.getInstance(CIPHER);
  65.                 IvParameterSpec iv = new IvParameterSpec("1234567812345678".getBytes());
  66.                 cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
  67.                 byte[] original = cipher.doFinal(content);
  68.                 String originalString = new String(original);
  69.                 return originalString;
  70.         }
  71.        
  72.         private SecretKeySpec getKey(String strKey) throws Exception {
  73.                 byte[] arrBTmp = strKey.getBytes();
  74.                 byte[] arrB = new byte[16]; // 创建一个空的16位字节数组(默认值为0)
  75.                 for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
  76.                         arrB[i] = arrBTmp[i];
  77.                 }
  78.                 SecretKeySpec skeySpec = new SecretKeySpec(arrB, ALGORITHM);
  79.  
  80.                 return skeySpec;
  81.         }
  82.         /**
  83.          * AES
  84.          * 将base 64 code AES解密
  85.          * @param encryptStr 待解密的base 64 code
  86.          * @param decryptKey 解密密钥
  87.          * @return 解密后的string
  88.          * @throws Exception
  89.          */
  90.         private String aesDecrypt(String encryptStr, String decryptKey) throws Exception {
  91.             return encryptStr.isEmpty() ? null : decrypt(base64Decode(encryptStr), decryptKey);
  92.         }
  93.  
  94.         /**
  95.          * base 64 decode
  96.          * @param base64Code 待解码的base 64 code
  97.          * @return 解码后的byte[]
  98.          * @throws Exception
  99.          */
  100.         private byte[] base64Decode(String base64Code) throws Exception{
  101.             return base64Code.isEmpty() ? null : new BASE64Decoder().decodeBuffer(base64Code);
  102.         }
  103.    
  104.     private String readFile(String filePath, String fileName) throws Exception {
  105.         String rtn = "";
  106.         byte[] data    = Files.readAllBytes(Paths.get(filePath, new String[]{fileName}));
  107.         rtn = new String(data, StandardCharsets.UTF_8);
  108.         return rtn;
  109.     }
  110.        
  111. }

Reply to "Read the file and use AES to decrypt it. If unsuccessful, exit the Java virtual machine"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website