java中使用异或的方式对文件进行加密解密
来源:互联网 发布:无线传感器软件 编辑:程序博客网 时间:2024/06/06 17:00
1.使用异或的方式加密文件的原理
一个数异或另一个数两次,结果一定是其本身
2.使用异或的原理加密文件
/** * 将文件内容加密 * 使用异或的方式将a.txt加密复制出一个b.txt,放到同一个文件夹下 */ @Test public void encryptFile(){ FileInputStream in = null; FileOutputStream out = null; try { String sourceFileUrl = "C:\\Users\\admin\\Desktop\\testIO\\a.txt"; String targetFileUrl = "C:\\Users\\admin\\Desktop\\testIO\\b.txt"; in = new FileInputStream(sourceFileUrl); out = new FileOutputStream(targetFileUrl); int data = 0; while ((data=in.read())!=-1){ //将读取到的字节异或上一个数,加密输出 out.write(data^1234); } }catch (Exception e){ e.printStackTrace(); }finally { //在finally中关闭开启的流 if (in!=null){ try { in.close(); } catch (IOException e) { e.printStackTrace(); } } if (out!=null){ try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } }
3.使用异或的原理解密文件
/** * 将文件内容解密 * 将使用异或的方式加密复制出的b.txt解密到c.txt,放到同一个文件夹下 */ @Test public void decryptFile(){ FileInputStream in = null; FileOutputStream out = null; try { String sourceFileUrl = "C:\\Users\\admin\\Desktop\\testIO\\b.txt"; String targetFileUrl = "C:\\Users\\admin\\Desktop\\testIO\\c.txt"; in = new FileInputStream(sourceFileUrl); out = new FileOutputStream(targetFileUrl); int data = 0; while ((data=in.read())!=-1){ //将读取到的字节异或上一个数,加密输出 out.write(data^1234); } }catch (Exception e){ e.printStackTrace(); }finally { //在finally中关闭开启的流 if (in!=null){ try { in.close(); } catch (IOException e) { e.printStackTrace(); } } if (out!=null){ try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } }
阅读全文
0 0
- java中使用异或的方式对文件进行加密解密
- java对文件简单的加密解密(异或运算)
- 使用异或对字符进行加密,解密。
- iOS中使用RNCryptor对文件进行AES加密/解密
- 使用CryptoAPI对文件进行加密解密
- java对文件进行加密解密操作
- 对使用zend加密后的php文件进行解密
- 使用Java对文件或文件夹的压缩, 解压, 加密和解密
- 使用AES算法对文件进行加密/解密的操作(JAVA)
- 对称加密算法AES------使用AES算法对文件进行加密/解密的操作(JAVA)
- 使用java对文件或文件夹进行压缩和加密
- 使用java对文件或文件夹进行压缩和加密
- 使用java对文件或文件夹进行压缩和加密
- 使用java对文件或文件夹进行压缩和加密
- 使用java对文件或文件夹进行压缩和加密
- 使用java对文件或文件夹进行压缩和加密
- 使用java对文件或文件夹进行压缩和加密
- Qt 使用异或进行加密解密
- 菜鸟:自己写了一个轮播代码供分为参考,如果有什么地方你有更好的方法,可以给我留言
- [日推荐]『表情集市』斗图必备
- 1.4算法研究-全排列
- SPOJ-COT-Count on a tree
- Dubbo配置以及使用总结
- java中使用异或的方式对文件进行加密解密
- C# SignalR 实时通讯 聊天室
- [转]ExtJS学习------Ext.window属性详解
- 简单的频道管理(第一步)
- DirectX9学习(一)
- 使用spring jdbc查询对象
- 写给立志做码农的大学生
- Spring实战之二:装配Bean
- Java NIO系列教程(七) FileChannel