资源简介
JAVA 实现的RSA加密算法,一个base64工具 ,一个RSA算法
代码片段和文件信息
package cn.com.csii.utility;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.codec.binary.base64;
/**
*
* base64编码解码工具包
*
*
* 依赖javabase64-1.3.1.jar
*
*
* @author IceWee
* @date 2012-5-19
* @version 1.0
*/
public class base64Utils {
/**
* 文件读取缓冲区大小
*/
private static final int CACHE_SIZE = 1024;
/**
*
* base64字符串解码为二进制数据
*
*
* @param base64
* @return
* @throws Exception
*/
public static byte[] decode(String base64) throws Exception {
base64 base64In = new base64();
return base64In.decode(base64.getBytes());
}
/**
*
* 二进制数据编码为base64字符串
*
*
* @param bytes
* @return
* @throws Exception
*/
public static String encode(byte[] bytes) throws Exception {
base64 base64In = new base64();
return new String(base64In.encode(bytes));
}
/**
*
* 将文件编码为base64字符串
*
*
* 大文件慎用,可能会导致内存溢出
*
*
* @param filePath 文件绝对路径
* @return
* @throws Exception
*/
public static String encodeFile(String filePath) throws Exception {
byte[] bytes = fileToByte(filePath);
return encode(bytes);
}
/**
*
* base64字符串转回文件
*
*
* @param filePath 文件绝对路径
* @param base64 编码字符串
* @throws Exception
*/
public static void decodeToFile(String filePath String base64) throws Exception {
byte[] bytes = decode(base64);
byteArrayToFile(bytes filePath);
}
/**
*
* 文件转换为二进制数组
*
*
* @param filePath 文件路径
* @return
* @throws Exception
*/
public static byte[] fileToByte(String filePath) throws Exception {
byte[] data = new byte[0];
File file = new File(filePath);
if (file.exists()) {
FileInputStream in = new FileInputStream(file);
ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
byte[] cache = new byte[CACHE_SIZE];
int nRead = 0;
while ((nRead = in.read(cache)) != -1) {
out.write(cache 0 nRead);
out.flush();
}
out.close();
in.close();
data = out.toByteArray();
}
return data;
}
/**
*
* 二进制数据写文件
*
*
* @param bytes 二进制数据
* @param filePath 文件生成目录
*/
public static void byteArrayToFile(byte[] bytes String filePath) throws Exception {
InputStream in = new ByteArrayInputStream(by 属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3647 2016-02-18 16:56 ba
文件 10507 2016-02-18 16:21 RSAUtils.java
- 上一篇:Student_Manage.zip
- 下一篇:jpcap资源
相关资源
- Java 文件加密传输
- C#和Java实现互通的RSADES加解密算法
- RSA数字签名算法的具体实现
- Rsa非对称加密的Java实现和举例更新版
- 完美使用RSA2结合AES对数据进行加密兼
- Android RSA加密jar包
- RSA算法JAVA公钥加密,C#私钥解密
- 支付宝RSA加解密工具
- RSA加密登录示例278136
- Android RSA加密解密文件
- RSA加密传输AES的key和iv js加密 java解
- RSA加密解密 JS加密 JAVA解密
- C# RSA加密、支持JAVA格式公钥私钥
- 基于JAVA的RSA文件加密软件的设计与实
- RSA加密解密JS加密JAVA解密
- javaweb使用rsa加密解密jar包
- RSA加解密源码及测试代码完整java工程
- JAVA的综合加解密聊天程序,附带文档
- MD5和RSA加密算法Java完成实现
- RSA前台加密后台解密Demo
- Java非对称加密源代码(RSA)-测试包
- android数据传输RSA加密DEMO
- javaRSA加密C++RSA解密
- android加密
- 安卓手机通用adb驱动UniversalAdbDriver官
- javafx_scenebuilder-2_0-macosx-universal.dmg
- RSA加密登录
- java实现简单RSA 公钥密码系统 源代码
- RSA算法与DES算法的实现
- Java 生成RSA密钥进行数据加密解密 支
川公网安备 51152502000135号
评论
共有 条评论