【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安全框架,提供了认证,授权,加密,和会话管理 ...
随机推荐
- printf ("%*.*s")
小数点.后“*”表示输出位数,具体的数据来自参数表printf格式字符串中,与宽度控制和精度控制有关的常量都可以换成变量,方法就是使用一个“*”代替那个常量,然后在后面提供变量给“*”. 同样,小数点 ...
- jenkins配置到gitlab拉代码
参照: jenkins 从git拉取代码-简明扼要 https://www.cnblogs.com/jwentest/p/7065783.html 持续集成①安装部署jenkins从git获取代码-超 ...
- 爱奇艺面试Python,竟然挂在第5轮…(转)
今天给大家分享我曾经在爱奇艺的面试,过程还是比较有意思的,可以给大家一些参考 聊骚阶段 嗲妹妹:你好,我是爱奇艺的HR,我们正在招聘运维开发岗位,请问您最近有在看工作机会吗? 我:(这声音也太酥了吧我 ...
- PAT 2019-3 7-3 Telefraud Detection
Description: Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, ...
- LeetCode6 dp
120. Triangle 我的解法用了一个二维数组,这样比较浪费空间.O(n*n) 但是标准答案自底向上,一是不需要进行特别判断,二是可以覆盖数组,则只需要O(n)的空间大小. class Solu ...
- leetcode.排序.215数组中的第k个最大元素-Java
1. 具体题目 在未排序的数组中找到第 k 个最大的元素.请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素. 示例 : 输入: [3,2,1,5,6,4] 和 k = ...
- db2别名&同义词
创建别名: create alias alias_name for tab_name|view_name... 删除别名: drop alias alias_name 创建同义词(synonym): ...
- [Java 教程 00] 计算机基础
前言 我想,来到这的朋友肯定是想学习JAVA或者想要进入IT这个行业的.考虑到大家的基础可能不一样,有些人可能还是用着新买的电脑,为了让大家在后续的学习中更加顺畅.在学习一门全新的计算机语言之前,我需 ...
- scroll兼容性
document.html=>document.documentElement function scroll() { if(window.pageYOffset != null) // ie9 ...
- 第十章 Ingress
一.资料信息 Ingress-Nginx github 地址:https://github.com/kubernetes/ingress-nginx Ingress-Nginx 官方网站:https: ...