文件读写BASE64解密、加密算法
2011-09-08 18:05
435 查看
import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; public class FileUtils { public static File saveFile(String fileContent, String filePath) throws IOException { if (fileContent == null) { return null; } BASE64Decoder decoder = new BASE64Decoder(); byte[] picBinary = decoder.decodeBuffer(fileContent); File file = new File(filePath); FileOutputStream out = new FileOutputStream(file); out.write(picBinary); out.close(); return file; } public static String readFile(String filePath) { try { sun.misc.BASE64Encoder encoder = new BASE64Encoder(); File file = new File(filePath); java.io.FileReader reader = new FileReader(file); char[] c = new char[1024]; // FileInputStream in = new FileInputStream(file); // byte[] b = new byte[1024]; StringBuffer buf = new StringBuffer(); int index = -1; while ((index = reader.read(c)) > 0) { buf.append(c, 0, index); } String result = encoder.encode(buf.toString().getBytes()); return result; } catch (Exception e) { e.printStackTrace(); } return null; } }
本文出自 “利他互联litalink.com” 博客,转载请与作者联系!
相关文章推荐
- 读取本地json文件,转出为指定格式json 使用Base64进行string的加密和解密
- 【python】读写base64文件
- 使用Base64加密解密文件
- C# DES 加密/解密类库,支持文件和中文/UNICODE字符,返回BASE64编码字符串
- eval(gzinflate(base64_decode无限加密文件的解密代码
- Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作
- Web.config配置文件的加密,解密及读写操作
- C# DES 加密/解密,支持文件和中文/UNICODE字符,返回BASE64编码字符串
- HTML 读写txt文件与转换base64编码
- java base64加密文件 及解密到文件
- Base64 解密,加密文件或者字符串 [本人加了字符串加解密]
- Java实现Base64给文件加密、解密
- python基于base64加密解密文件
- 用base64加密解密文件
- VB-Base64 文件或字符加解密
- C# DES 加密/解密,支持文件和中文/UNICODE字符,返回BASE64编码字符串
- base64随机字符混淆加密、解密-美拍视频地址解密,反推加密算法
- base64编码和aes加密和解密配置文件
- c语言加密算法头文件下载(base64、md5、sha1)
- 加密算法学习以及base64加密解密应用