我以前在.NET里面是这样做的:
public static string Encrypt(string str)
{
UnicodeEncoding code = new UnicodeEncoding();
byte[] bytes = code.GetBytes(str);
byte[] hashValue = ((HashAlgorithm)CryptoConfig.CreateFromName("SHA")).ComputeHash(bytes);
return Convert.ToBase64String(hashValue);
}
现在,这些加密的口令已经存到数据库里面了,我想用Java来实现同样的功能,请问我应该如何做呢?请高手赐教!
public static string Encrypt(string str)
{
UnicodeEncoding code = new UnicodeEncoding();
byte[] bytes = code.GetBytes(str);
byte[] hashValue = ((HashAlgorithm)CryptoConfig.CreateFromName("SHA")).ComputeHash(bytes);
return Convert.ToBase64String(hashValue);
}
现在,这些加密的口令已经存到数据库里面了,我想用Java来实现同样的功能,请问我应该如何做呢?请高手赐教!
解决方案 »
- Java 中 .setVisible(false);之后是否还在运行?
- 新浪微博xauth认证问题
- 如何在java 的class文件中的jvm字节码定位对应回到java源程序的某一行?
- JTextPane的颜色问题,高手请进
- 日期型的数据如何相减,计算出相差的天数是多少?
- 求助,又是中文问题
- 模仿junit 4 对main 方法的测试 求改进
- 请问jbuilder中有没有类似于Vb中的ListView的组件
- 这套CD究竟什么样子啊?
- 急!急!急!我的页面有VRML场景,同时有javaAPPLET,怎样由场景向APPLET发送消息或交互
- 救命啊!
- Bigger type length than Maximum
很详细