图片加密解密小知识

代码如下

public static void main(String[] args) {
        //输入流,图片路径(相对路径),加密
        try {
            FileInputStream fis = new FileInputStream("pic/绿茶.jpg");
            FileOutputStream fos = new FileOutputStream("pic/绿茶_last.jpg");//加密后文件名
            int b;
            try {
                while((b = fis.read()) != -1){
                    fos.write(b^1234);
                }
            }
            catch (IOException e) {//捕捉IO 异常
                e.printStackTrace();
            }
        }
        catch (FileNotFoundException e) {//捕捉File找不到异常
            e.printStackTrace();
        }
    }
public static void main(String[] args) {
      //输入流,图片路径(相对路径),解密
        try {
            FileInputStream fis = new FileInputStream("pic/绿茶_last.jpg");
            FileOutputStream fos = new FileOutputStream("pic/绿茶解密.jpg");//加密后文件名
            int b;
            try {
                while((b = fis.read()) != -1){
                    fos.write(b^1234);
                }
            }
            catch (IOException e) {//捕捉IO 异常
                e.printStackTrace();
            }
        }
        catch (FileNotFoundException e) {//捕捉File找不到异常
            e.printStackTrace();
        }
    }

初学者如有疑问,留言联系,谢谢……

原文地址:https://www.cnblogs.com/wanghui1316/p/5470440.html