博客
关于我
java实现简单文件加密解密
阅读量:609 次
发布时间:2019-03-12

本文共 694 字,大约阅读时间需要 2 分钟。

/** * 加密解密 * @param filePath 文件路径 * @param code 加密解密码 * @throws IOException * @return 加密后文件生成路径 */public static String enOrDecryption(String filePath,int code) throws IOException {    if(filePath==null||filePath.trim().equals("")){        return "";    }    File oldFile=new File(filePath);    //原文件输入流    FileInputStream fis=new FileInputStream(oldFile);    //加密后文件输出流    File newFile=new File(oldFile.getParent(),"m"+oldFile.getName());    FileOutputStream fos=new FileOutputStream(newFile);    while (true){        int i=fis.read();        if(i==-1) break;        //异或操作:X^A^A=X^(A^A)=X^0=X        fos.write(i^code);    }    fis.close();    fos.close();    return newFile.getAbsolutePath();}

 

转载地址:http://kgtxz.baihongyu.com/

你可能感兴趣的文章
mqtt broker服务端
查看>>
MQTT 保留消息
查看>>
MQTT 持久会话与 Clean Session 详解
查看>>
MQTT工作笔记0007---剩余长度
查看>>
MQTT工作笔记0009---订阅主题和订阅确认
查看>>
Mqtt搭建代理服务器进行通信-浅析
查看>>
MS Edge浏览器“STATUS_INVALID_IMAGE_HASH“兼容性问题
查看>>
ms sql server 2008 sp2更新异常
查看>>
MS UC 2013-0-Prepare Tool
查看>>
MSBuild 教程(2)
查看>>
msbuild发布web应用程序
查看>>
MSB与LSB
查看>>
MSCRM调用外部JS文件
查看>>
MSCRM调用外部JS文件
查看>>
MSEdgeDriver (Chromium) 不适用于版本 >= 79.0.313 (Canary)
查看>>
MsEdgeTTS开源项目使用教程
查看>>
msf
查看>>
MSSQL数据库查询优化(一)
查看>>
MSSQL数据库迁移到Oracle(二)
查看>>
MSSQL日期格式转换函数(使用CONVERT)
查看>>