【Shiro】五、Apache Shiro加密
Shiro提供了更好封装,更好使用的加密算法API,可以作为平时使用的一个工具类的预选方案。
Shiro的密码学
基本特性
接口驱动,基于POJO
对JCE(Java Cryptography Extension)的简单封装
面向对象的加密概念
加密特性
接口默认实现
内置Hex和Base64转换
内置加盐和散列支持
编码/解码
@Test
public void testBase64(){
String str = "hello";
String base64Encoded = Base64.encodeToString(str.getBytes());
String str2 = Base64.decodeToString(base64Encoded);
Assert.assertEquals(str,str2);
} @Test
public void testHex(){
String str = "hello";
String base64Encoded = Hex.encodeToString(str.getBytes());
String str2 = new String(Hex.decode(base64Encoded.getBytes()));
Assert.assertEquals(str, str2);
}
散列算法
普通用法
@Test
public void testMd5(){
String str = "hello";
String salt = "123";
String md5 = new Md5Hash(str, salt).toString();
System.out.println(md5);
} @Test
public void testSha256(){
String str = "hello";
String salt = "123";
String sha1= new Sha256Hash(str, salt).toString();
System.out.println(sha1);
} @Test
public void testSimpleHash(){
String str = "hello";
String salt = "123";
String simpleHash= new SimpleHash("SHA-1", str, salt).toString();
System.out.println(simpleHash);
}
高级用法,提供更多可配置项






【Shiro】五、Apache Shiro加密的更多相关文章
- 【Shiro】Apache Shiro架构之身份认证(Authentication)
Shiro系列文章: [Shiro]Apache Shiro架构之权限认证(Authorization) [Shiro]Apache Shiro架构之集成web [Shiro]Apache Shiro ...
- 【Shiro】Apache Shiro架构之自定义realm
[Shiro]Apache Shiro架构之身份认证(Authentication) [Shiro]Apache Shiro架构之权限认证(Authorization) [Shiro]Apache S ...
- 【Shiro】Apache Shiro架构之集成web
Shiro系列文章: [Shiro]Apache Shiro架构之身份认证(Authentication) [Shiro]Apache Shiro架构之权限认证(Authorization) [Shi ...
- 【Shiro】Apache Shiro架构之权限认证(Authorization)
Shiro系列文章: [Shiro]Apache Shiro架构之身份认证(Authentication) [Shiro]Apache Shiro架构之集成web [Shiro]Apache Shir ...
- [转载] 【Shiro】Apache Shiro架构之实际运用(整合到Spring中)
写在前面:前面陆陆续续对Shiro的使用做了一些总结,如题,这篇博文主要是总结一下如何将Shiro运用到实际项目中,也就是将Shiro整到Spring中进行开发.后来想想既然要整,就索性把Spring ...
- Apache Shiro 手册
(一)Shiro架构介绍 一.什么是Shiro Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能: 认证 - 用户身份识别,常被称为用户"登录 ...
- Apache Shiro 使用手册---转载
原文地址:http://www.360doc.com/content/12/0104/13/834950_177177202.shtml (一)Shiro架构介绍 一.什么是Shiro Apache ...
- Apache Shiro 使用手册
http://kdboy.iteye.com/blog/1154644 (一)Shiro架构介绍 一.什么是Shiro Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加 ...
- 让Apache Shiro保护你的应用
在尝试保护你的应用时,你是否有过挫败感?是否觉得现有的Java安全解决方案难以使用,只会让你更糊涂?本文介绍的Apache Shiro,是一个不同寻常的Java安全框架,为保护应用提供了简单而强大的方 ...
- Apache Shiro 快速入门教程,shiro 基础教程 (这篇文章非常好)
第一部分 什么是Apache Shiro 1.什么是 apache shiro : Apache Shiro是一个功能强大且易于使用的Java安全框架,提供了认证,授权,加密,和会话管理 ...
随机推荐
- Vue.js 计算属性
Vue.js 计算属性 使用计算属性的实例: <!DOCTYPE html> <html> <head> <meta cahrset="utf-8& ...
- sql查询某个时间内的数据
hour) 七天之前的数据 SELECT * FROM commodity_order where create_time <= (now()-INTERVAL 7 DAY) order by ...
- jmeter添加自定义扩展函数之图片base64
原文连接:---------https://www.cnblogs.com/qiaoyeye/p/7218770.html----------- 打开eclipse,新建maven工程,在pom中引用 ...
- Cygwin访问windows磁盘目录
http://blog.csdn.net/duguduchong/article/details/7680650 Cygwin访问windows磁盘目录 标签: windows磁盘user平台c 2 ...
- do_mmap解读
1: unsigned long do_mmap_pgoff(struct file *file, unsigned long addr, 2: unsigned long len, unsigned ...
- Python中的装饰器,迭代器,生成器
1. 装饰器 装饰器他人的器具,本身可以是任意可调用对象,被装饰者也可以是任意可调用对象. 强调装饰器的原则:1 不修改被装饰对象的源代码 2 不修改被装饰对象的调用方式 装饰器的目标:在遵循1和2的 ...
- FileInputStream_FileOutputStream
Writer的基本方法 //向输出流中写入一个字符数据,该字节数据为参数b的低16位 void write(int c) throws IOException //将一个字符类型的数组中的数据写入输出 ...
- JVM系列(二) — Java垃圾收集介绍
这篇文章主要从以下几个方面介绍垃圾收集的相关知识 一.判断对象是否已死 二.主流垃圾收集算法 三.内存分配与回收策略 本章节主要从以下几个思考点着手介绍垃圾回收的相关知识:哪些内存需要回收?什么时候回 ...
- 面相对象编程 扩充之封装、访问机制、 property
封装: 封装指的是可以将一堆属性和方法,封装到对象中 ps : 对象就好比一个 “袋子/容器”, 可以存放一堆属性和方法 ps : 存不是目的,目的是为了取,可以通过“对象” d的方式获取属性或方法 ...
- C#设计模式:状态者模式(State Pattern)
一,什么是状态设计模式? 1,定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新. 2,当一个对象的内部状态改变时允许改变其行为,这个对象看起来像是 ...