import java.io.*;
/**
 * 这是一个简单的利用异或加密和解密的简单程序
 * @author sagomilk
 * @version 20140805
 */
public class Encrypt {
	private static final int PASSWORD = 0x12345678;
	private static final String SUFFIX = ".ecpt";

	/**
	 * 加密方法
	 * @param path [需要加密的文件路径]
	 * @return [没有返回值]
	 */
	public void encrypt(String path) {
		FileInputStream in = null;
		FileOutputStream out = null;

		try {
			int tmp = 0;
			File inFile = new File(path);
			in = new FileInputStream(inFile);
			File outFile = new File(path + SUFFIX);
			out = new FileOutputStream(outFile);
			while ((tmp = in.read()) != -1) {
				out.write(tmp^PASSWORD);
			}


		} catch (FileNotFoundException e) {
			System.out.println("File not exist. ");
		} catch (IOException e) {
			System.out.println("Read file exception ");
		} finally {
			try {
				if (in != null) {
					in.close();
				}

				if (out != null) {
					out.close();
				}
			} catch (IOException e) {
				System.out.println("Close resouce fail");
			}
		}
	}

	/**
	 * 解密方法
	 * @param path [需要解密的文件路径]
	 * @return [没有返回值]
	 */
	public void decrypt(String path) {
		int index = path.lastIndexOf(SUFFIX);

		if (index != path.length() - SUFFIX.length()) {
			System.out.println("file type error");
			return;
		}

		FileInputStream in = null;
		FileOutputStream out = null;
		try {
			int tmp = 0;
			File inFile = new File(path);
			in = new FileInputStream(inFile);

			String name = path.substring(0, index);
			File outFile = new File(name);

			out = new FileOutputStream(outFile);

			while ((tmp = in.read()) != -1) {
				out.write(tmp^PASSWORD);
			}


		} catch (FileNotFoundException e) {
			System.out.println("File not exist. ");
		} catch (IOException e) {
			System.out.println("Read file exception ");
		} finally {
			try {
				if (in != null) {
					in.close();
				}

				if (out != null) {
					out.close();
				}
			} catch (IOException e) {
				System.out.println("Close resouce fail");
			}
		}

	}

	/**
	 * 简单的加密与解密测试
	 * @param args [调用java命令的时候传入的参数列表]
	 */
	public static void main(String[] args) {
		Encrypt e = new Encrypt();

		if (args.length != 2) {
			System.out.println("args number unmatch 2");
			return;
		}

		String param = args[0];
		String path = args[1];

		if (param.equalsIgnoreCase("-e")) {
			e.encrypt(path);
		} else if (param.equalsIgnoreCase("-d")) {
			e.decrypt(path);
		}
	}
}
@@ -2069,24 +2069,48 @@
 Encrypt();%0A%0A
+%09%09// %E7%AE%80%E5%8D%95%E9%80%BB%E8%BE%91%E5%88%A4%E6%96%AD%EF%BC%8C%E5%8F%82%E6%95%B0%E4%B8%8D%E7%AC%A6%E5%90%88%E8%A6%81%E6%B1%82%E7%9B%B4%E6%8E%A5%E9%80%80%E5%87%BA%0A
 %09%09if (args.l
@@ -2239,16 +2239,52 @@
 gs%5B1%5D;%0A%0A
+%09%09// %E7%9B%AE%E5%89%8D%E6%94%AF%E6%8C%812%E7%A7%8D%E5%8F%82%E6%95%B0%0A%09%09// -e %E5%8A%A0%E5%AF%86%0A%09%09// -d %E8%A7%A3%E5%AF%86%0A
 %09%09if (pa

Encrypt | add annotation