Java Encrypt File encryptFile(InputStream in, String dstFile)

Here you can find the source of encryptFile(InputStream in, String dstFile)

Description

encrypt File

License

Open Source License

Declaration

public static void encryptFile(InputStream in, String dstFile) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

public class Main {
    static final byte[] KEYVALUE = "6^)(9-@=+@j.&6^)(p35@%3%!#O@*GpG0#4S!4S0)$Y%%Y-=+".getBytes();
    static final int BUFFERLEN = 1024;

    public static void encryptFile(InputStream in, String dstFile) throws Exception {
        File file = new File(dstFile);
        if (!file.exists())
            file.createNewFile();//from w  ww  .  ja v  a2  s  .  co m
        FileOutputStream out = new FileOutputStream(file);
        int c, pos, keylen;
        pos = 0;
        keylen = KEYVALUE.length;
        byte buffer[] = new byte[BUFFERLEN];
        while ((c = in.read(buffer)) != -1) {
            for (int i = 0; i < c; i++) {
                buffer[i] ^= KEYVALUE[pos];
                out.write(buffer[i]);
                pos++;
                if (pos == keylen)
                    pos = 0;
            }
        }
        in.close();
        out.close();
    }
}