JAVA用OPENSSL计算文件的SHA1值,并以BASE64格式保存
来源:互联网 发布:keepalived 算法 编辑:程序博客网 时间:2024/05/21 17:02
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import sun.misc.BASE64Encoder;
public class MDCalculationTest ...{
public MDCalculationTest(String fileName) ...{
FileInputStream fis = null;
BufferedInputStream bufferedInputStream = null;
try ...{
System.out.println("programing begin....");
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
System.out.println(df.format(new Date()));
MessageDigest alga = MessageDigest.getInstance("SHA-1");
File file = new File(fileName);
if (!file.exists() || file.isDirectory()) ...{
throw new FileNotFoundException("file is not exsit!");
}
fis = new FileInputStream(file);
bufferedInputStream = new BufferedInputStream(fis);
byte[] bt = new byte[4096];
int tmp = 0;
while (true) ...{
tmp = bufferedInputStream.read(bt, 0, bt.length);
if (tmp < 0) ...{
break;
}
Thread.yield();
alga.update(bt, 0, tmp);
}
byte[] digesta = alga.digest();
BASE64Encoder base64 = new BASE64Encoder();
String result = base64.encode(digesta);
System.out.println("base64 encode's result is = " + result);
System.out.println(df.format(new Date()));
} catch (NoSuchAlgorithmException e) ...{
e.printStackTrace();
} catch (FileNotFoundException e) ...{
e.printStackTrace();
} catch (IOException e) ...{
e.printStackTrace();
} finally ...{
if (bufferedInputStream != null) ...{
try ...{
bufferedInputStream.close();
} catch (IOException e) ...{
e.printStackTrace();
}
}
}
}
public static void main(String args[]) ...{
if (args == null || args.length == 0) ...{
System.out.println("please input the fullpath of an file. then excute again!");
return;
}
MDCalculationTest test = new MDCalculationTest(args[0]);
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import sun.misc.BASE64Encoder;
public class MDCalculationTest ...{
public MDCalculationTest(String fileName) ...{
FileInputStream fis = null;
BufferedInputStream bufferedInputStream = null;
try ...{
System.out.println("programing begin....");
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
System.out.println(df.format(new Date()));
MessageDigest alga = MessageDigest.getInstance("SHA-1");
File file = new File(fileName);
if (!file.exists() || file.isDirectory()) ...{
throw new FileNotFoundException("file is not exsit!");
}
fis = new FileInputStream(file);
bufferedInputStream = new BufferedInputStream(fis);
byte[] bt = new byte[4096];
int tmp = 0;
while (true) ...{
tmp = bufferedInputStream.read(bt, 0, bt.length);
if (tmp < 0) ...{
break;
}
Thread.yield();
alga.update(bt, 0, tmp);
}
byte[] digesta = alga.digest();
BASE64Encoder base64 = new BASE64Encoder();
String result = base64.encode(digesta);
System.out.println("base64 encode's result is = " + result);
System.out.println(df.format(new Date()));
} catch (NoSuchAlgorithmException e) ...{
e.printStackTrace();
} catch (FileNotFoundException e) ...{
e.printStackTrace();
} catch (IOException e) ...{
e.printStackTrace();
} finally ...{
if (bufferedInputStream != null) ...{
try ...{
bufferedInputStream.close();
} catch (IOException e) ...{
e.printStackTrace();
}
}
}
}
public static void main(String args[]) ...{
if (args == null || args.length == 0) ...{
System.out.println("please input the fullpath of an file. then excute again!");
return;
}
MDCalculationTest test = new MDCalculationTest(args[0]);
}
}
- JAVA用OPENSSL计算文件的SHA1值,并以BASE64格式保存
- C用OPENSSL计算文件的SHA1值,并以BASE64格式保存
- Android将图上以base64编码的格式上传到node.js服务器并保存
- Android/java 计算大文件的SHA1值
- QT界面设计并保存到文件(以JSON格式)
- PHP保存base64格式的图片内容为图片文件
- 使用openssl就算文件的MD5和SHA1值
- 如何用JAVA将二进制文件转换成BASE64格式保存到MySQL的Blob字段里并读出下载
- php将一个txt文件用base64编码并保存
- 关于实现接收base64图片数据并以图片保存到本地的处理
- JAVA计算文件的MD5及SHA1等值
- OPENSSL之计算SHA1散列值
- 在 gradle文件里计算文件的sha1值
- base64格式的图片转换成图片并保存(ASP.NET)
- Java实现base64图片转换为base64字符串。base64字符串转换图片 之间的互相转换,并保存在本地。
- 使用openssl库EVP编程计算sha1值
- Qt 中实现 hmac Sha1 加密并以 base64编码输出
- PHP处理ajax提交的裁剪后的base64的图片并保存 以cropbox.js控件为例
- DB2基本概念
- 破戒
- 定时任务执行
- 调用编译器接口ICodeCompiler实现数学表达式计算
- 结婚的参考一下
- JAVA用OPENSSL计算文件的SHA1值,并以BASE64格式保存
- 实现自动刷新页面的几点注意
- J2ME专业手机游戏开发基础(1)
- 关于Oracle数据库的用户对象配置以及数据镜像的总结
- J2ME专业手机游戏开发基础(2)
- 在公司看到的好文章精华
- [轻松一下]世界上至少有10種東西是你不知道的
- Windows下网络数据报的监听和拦截技术
- NHibernate的Session管理