必威体育Betway必威体育官网
当前位置:首页 > IT技术

111111111111111111

时间:2019-08-01 07:11:19来源:IT技术作者:seo实验室小编阅读:80次「手机版」
 

111111111111111111

    public static void encrypt(String fileUrl, String key) throws Exception {
        File file = new File(fileUrl);
        String path = file.getPath();
        if (!file.exists()) {
            return;
        }
        int index = path.lastindexof("\\");
        int index2 = path.lastIndexOf("4");
        String path3 = path.substring(index+1, index2+1);
        String destFile = "H:\\xiangmu\\streammedia\\WebRoot\\movies\\"+path3;
        System.out.println(destFile);
        File dest = new File(destFile);
        InputStream in = new fileinputstream(fileUrl);
        outputstream out = new FileOutputStream(destFile);
        byte[] buffer = new byte[1024];
        int r;
        byte[] buffer2 = new byte[1024];
        while ((r = in.read(buffer)) > 0) {
            for (int i = 0; i < r; i++) {
                byte b = buffer[i];
                buffer2[i] = b == 255 ? 0 : ++b;
            }
            out.write(buffer2, 0, r);
            out.flush();
        }
        in.close();
        out.close();
        file.delete();
        dest.renameTo(new File(fileUrl));
        APPendMethodA(destFile, key);
        System.out.println("加密成功");
    }
		
    public static void appendMethodA(String fileName, String content) {
        try {
            // 打开一个随机访问文件流,按读写方式
            RandomAccessFile randomFile = new RandomAccessFile(fileName, "rw");
            // 文件长度,字节数
            long fileLength = randomFile.length();
            // 将写文件指针移到文件尾。
            randomFile.seek(fileLength);
            randomFile.writeBytes(content);
            randomFile.close();
        } catch (IOException e) {
            e.printstacktrace();
        }
    }

public static String decrypt(String fileUrl, String tempUrl, int keyLength)
            throws Exception {
        File file = new File(fileUrl);
        if (!file.exists()) {
            return null;
        }
        File dest = new File(tempUrl);
        if (!dest.getparentFile().exists()) {
            dest.getParentFile().mkdirs();
        }

        InputStream is = new FileInputStream(fileUrl);
        OutputStream out = new FileOutputStream(tempUrl);

        byte[] buffer = new byte[1024];
        byte[] buffer2 = new byte[1024];
        byte bMax = (byte) 255;
        long size = file.length() - keyLength;
        int mod = (int) (size % 1024);
        int p = (int) (size >> 10);
        int count = mod == 0 ? p : (p + 1);
        int k = 1, r;
        while ((k <= count && (r = is.read(buffer)) > 0)) {
            if (mod != 0 && k == count) {
                r = mod;
            }

            for (int i = 0; i < r; i++) {
                byte b = buffer[i];
                buffer2[i] = b == 0 ? bMax : --b;
            }
            out.write(buffer2, 0, r);
            k++;
        }
        out.close();
        is.close();
        return tempUrl;
    }

public static boolean findProcess(String processName) {BufferedReader br = null; try { Process proc = runtime.getRuntime().exec("tasklist.exe /fo csv /nh"); br = new BufferedReader(new inputstreamreader(proc.getInputStream())); System.out.println("Process info:"); String line; while ((line = br.readLine()) != null) { System.out.println(br.readLine()); if (line.contains(processName)) { return true; } } } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { //br.close(); } catch (Exception e) { e.printStackTrace(); } } }return false; }

相关阅读

分享到:

栏目导航

推荐阅读

热门阅读