Apache shiro 笔记整理之加密
2016-03-03 20:56
591 查看
以下内容是在看了涛哥的《跟我一起学shiro》 和 视频《一头扎入进shiro》 后整理出来备忘和方便自己和其他人学习。
shiro加密
Base64加密:
这样不好,因为容易被破解
md5加密:
加盐加密,不可逆,如果对方不知道盐,是很难破解的。推荐使用
实际开发中:保存在用户表中的密码是加密后的密码,这样可以保障数据的安全性。用户输入的密码为password;而保存到数据库的密码为saltPassword。但用户访问时,将password进行md5加盐加密后与数据库中的saltPassword匹配,若一致则登入。
shiro加密
Base64加密:
package com.shiro.utils; import org.apache.shiro.codec.Base64; public class CryptographyUtil { /** * base64 加密 * @param string * @return */ public static String encBase64(String string) { return Base64.encodeToString(string.getBytes()); } /** * Base64 解密 * @param string * @return */ public static String decBase64(String string) { return Base64.decodeToString(string); } public static void main(String[] args) { String password = "ITDragon博客"; String encBase64 = encBase64(password); String decBase64 = decBase64(encBase64); System.out.println("加密密码: " + encBase64 + " \n解密密码: " + decBase64); } }
这样不好,因为容易被破解
md5加密:
加盐加密,不可逆,如果对方不知道盐,是很难破解的。推荐使用
/** * md5 加密 * @param string * @param salt * @return */ public static String md5(String string , String salt) { return new Md5Hash(string, salt).toString(); }
实际开发中:保存在用户表中的密码是加密后的密码,这样可以保障数据的安全性。用户输入的密码为password;而保存到数据库的密码为saltPassword。但用户访问时,将password进行md5加盐加密后与数据库中的saltPassword匹配,若一致则登入。
相关文章推荐
- Apache Kafka:下一代分布式消息系统
- (1) PHP 随笔---跟老韩学(24-34)---Apache、PHP简介、环境的搭建
- 在本地使用Apache配置WEB服务器
- Eclipse使用Maven创建Web时错误:Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webap
- org.apache.subversion.javahl.ClientException: Previous operation has not finished
- Apache Thrift - 可伸缩的跨语言服务开发框架
- 闰年2月29号 通过apache的ftp工具从ftp上下载文件失败
- Windows 64位系统安装Apache2.4 mysql5.5
- Apache之AllowOverride参数详解
- Apache中的SetEnvIf是什么?
- MAC下用homebrew安装及配置apache、php和mysql
- Linux下编译安装Apache及模块
- apache配置vhosts
- JMS两种模型,布上apache-activemq服务器JMS(四)
- Djang+Wsgi+Apache Config
- linux ---apache的安装和配置
- Apache配置虚拟主机域名
- apache实现多域名虚拟主机的SSL认证
- Apache Shiro通俗易懂
- 用Apache和mod_wsgi配置Python应用的教程