----------- android培训、java培训、java学习型技术博客、期待与您交流! ------------
/*
需求:对图片加密。
分析:用异或来异或图片文件再保存。原理就是一个数异或一个数两次还是本数。
*/
import java.io.*;
class JiaMi
{
public static void main(String[] args)
{
jiaMi();
}
public static void jiaMi()
{
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
File file = new File("D:\\day01\\a.jpg");
File file1 = new File("D:\\b.jpg");
try
{
bis = new BufferedInputStream(new FileInputStream(file));
bos = new BufferedOutputStream(new FileOutputStream(file1));
int num = 0;
while ((num = bis.read()) != -1)
{
bos.write(num ^ 0xff);
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
finally
{
try
{
if(bis != null)
bis.close();
}
catch (IOException e)
{
throw new RuntimeException(e);
}
try
{
if(bos != null)
bos.close();
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
}
}
----------- android培训 、 java培训 、java学习型技术博客、期待与您交流! ------------
本文介绍了一种简单的图片加密方法,通过使用异或运算对图片文件进行加密处理。具体实现上,程序读取原始图片文件的每个字节,并将其与0xff进行异或操作,然后将处理后的数据写入新的图片文件中完成加密过程。

1269

被折叠的 条评论
为什么被折叠?



