【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安全框架,提供了认证,授权,加密,和会话管理 ...
随机推荐
- Buuctf | sqli-labs
这个是赵师傅给我们提供的训练靶场,最好都打一遍,但是出于找flag的角度,特此记录一下,flag在哪里[没错,我就是喜欢我的蓝变红,哈] ?id=1' :报错,说明就是用这个闭合的 ?id=0' un ...
- [CSP-S模拟测试]:壕游戏(费用流)
题目传送门(内部题18) 输入格式 第一行包括四个数$n,m,k,s$表示有$n$个剧情点,$m$个关卡,要玩$k$次游戏,$s$个完结点接下来一行包含$s$个数,代表$s$个完结点的编号.接下来$m ...
- Win7、Win10、Linux局域网文件共享
目录 1.WIN7系统局域网文件共享 2.WIN10系统局域网文件共享 3.Linux 局域网文件共享 WIN7系统局域网文件共享 步骤一: 打开网络和共享中心----更改高级共享设置 步骤二: 选择 ...
- 初识 ❤ TensorFlow |【一见倾心】
说明
- 20175213 2018-2019-2 《Java程序设计》第11周学习总结
教材学习内容总结 URL类是java.net包中的一个重要的类,URL的实例封装着一个统一资源定位符(Uniform Resource Locator),使用URL创建对象的应用程序称作客户端程序 U ...
- Go的struct
1. 前言 Go的struct声明允许字段附带Tag来对字段做一些标记. 该Tag不仅仅是一个字符串那么简单,因为其主要用于反射场景,reflect包中提供了操作Tag的方法,所以Tag写法也要遵循一 ...
- bzoj 2242: [SDOI2011]计算器 & BSGS算法笔记
这题的主要难点在于第三问该如何解决 于是就要知道BSGS是怎样的一种方法了 首先BSGS是meet in the middle的一种(戳下面看) http://m.blog.csdn.net/blog ...
- 如何在列表,字典,集合中,根据条件筛选数据 -- Python数据结构与算法相关问题与解决技巧
实际案例: 1.过滤掉列表 [3,9,-1,10,20,-2..]的负数 2.筛出字典{'LiLei':79,'Jim':88,'Lucy':92...}中值高于90的项 3.筛出集合 {77,89, ...
- python 装饰器 第一步:基本函数
# 第一步:基本函数 def eat(): print('吃饭') # 调用 eat()
- Vue 创建组件的两种方法
地址:https://blog.csdn.net/cofecode/article/details/74634301 创建组件的两种方法 1.全局注册 2.局部注册 var child=Vue.ext ...