/**
* Encode a string using algorithm specified in web.xml and return the
* resulting encrypted password. If exception, the plain credentials
* string is returned
*
* @param password Password or other credentials to use in authenticating
* this username
* @param algorithm Algorithm used to do the digest(加密算法:MD5,SHA)
*
* @return encypted password based on the algorithm.
*/
public static String encodePassword(String password, String algorithm) {
byte[] unencodedPassword = password.getBytes();
MessageDigest md = null;
try {
// first create an instance, given the provider
md = MessageDigest.getInstance(algorithm);
} catch (Exception e) {
mLogger.error("Exception: " + e);
return password;
}
md.reset();
// call the update method one or more times
// (useful when you don't know the size of your data, eg. stream)
md.update(unencodedPassword);
// now calculate the hash
byte[] encodedPassword = md.digest();
StringBuffer buf = new StringBuffer();
for (int i = 0; i < encodedPassword.length; i++) {
if ((encodedPassword[i] & 0xff) < 0x10) {
buf.append("0");
}
buf.append(Long.toString(encodedPassword[i] & 0xff, 16));
}
return buf.toString();
}
/**
* Encode a string using Base64 encoding. Used when storing passwords
* as cookies.
*
* This is weak encoding in that anyone can use the decodeString
* routine to reverse the encoding.
*
* @param str
* @return String
* @throws IOException
*/
public static String encodeString(String str) throws IOException {
Base64 base64 = new Base64();
String encodedStr = new String(base64.encodeBase64(str.getBytes()));
return (encodedStr.trim());
}
/**
* Decode a string using Base64 encoding.
*
* @param str
* @return String
* @throws IOException
*/
public static String decodeString(String str) throws IOException {
Base64 base64 = new Base64();
String value = new String(base64.decodeBase64(str.getBytes()));
return (value);
}
分享到:
相关推荐
Roller 是一个全功能的多用户博客平台,于2002年首发,采用Java语言开发,设计精巧,源代码是很好的学习资料。它支持weblogging应有的特性如:评论功能,所见即所得HTML编辑,TrackBack,提供页面模板,RSS ...
Roller 是一个全功能的多用户博客平台,于2002年首发,采用Java语言开发,设计精巧,源代码是很好的学习资料。它支持weblogging应有的特性如:评论功能,所见即所得HTML编辑,TrackBack,提供页面模板,RSS ...
阅读优秀项目源代码是提高Java开发水平,弥补项目经验不足的最佳途径! 现奉上丰盛的Java源代码大餐——apache优秀Java开源博客项目源代码 apache-roller!
开源博客代码,ROller最新代码,使用MAVEN、JPA、STRUTS等技术实现,很好的学习工具
开源博客 支持多用户 在tomcat 直接能运行 要配置一下roller-customer.properties 有问题 访问www.willvc.com.cn能联系到我
与大多数骰子滚子不同,Dragon Roller是与Dungeons&Dragons:registered:一起使用的独特工具,Dragon Roller会自动为所有掷骰子创建可导出的日志。
NULL 博文链接:https://moving200x.iteye.com/blog/1749902
Apache Roller是一个全功能,多用户和组博客服务器,适合大型和小型博客网站。它运行一个Java Web应用程序应该能够运行在任何Java EE服务器和关系数据库。目前,Apache Roller能很好的支持Tomcat和MySQL。 本人用...
Roller 是一个全功能的多用户博客平台,于2002年首发,采用Java语言开发,设计精巧,源代码是很好的学习资料。它支持weblogging应有的特性如:评论功能,所见即所得HTML编辑,TrackBack,提供页面模板,RSS ...
weblogging 设计比较精巧,是很好的学习资料。它支持weblogging应有的特性如:评论功能,所见即所得HTML编辑,TrackBack,提供页面模板,RSS syndication,blogroll管理和提供一个XML-RPC 接口。 最主要是其开源
roller-user-guide.pdf java blog 开源 opensource
Safety evaluation of table liner for vertical roller mill by modified fatigue limit
GNOME环境的存档管理器。
Encrypt-roller 是一个加密/解密包。 该项目的目标是结合多种加密方案和机制,为存储或传输的文件提供安全性和有效性。
apache-roller-srapaapache-roller-srcche-roller-srccapache-rolaapache-roller-srcpache-roller-srcler-srcapapache-roller-srcache-roller-srcapache-roller-src
NULL 博文链接:https://jarorwar.iteye.com/blog/554942
apache-rollapachapache-roller-srce-roller-srcer-srcapache-rolleapacapache-roller-srche-roller-srcr-srcapache-roapache-roller-srcller-srcapache-roller-src
apache-roller-src apache-roller-src apache-roller-src apache-roller-src apache-roller-src apache-roller-src apache-roller-src apache-roller-src apache-roller-src apache-roller-src