当前位置: 首页 > news >正文

政府网站外文版建设评估app开发费用

政府网站外文版建设评估,app开发费用,网上购物系统功能模块,网站建设w亿码酷1流量订制目录 前言 一、登录认证密码加密 二、bcrypt加密密码不一样,匹配原理 1.程序运行现象 2.原理解释 三、密码防重放 总结 前言 密码重放攻击:请求被攻击者获取,并重新发送给认证服务器,从而达到认证通过的目的 一、登录认证密…

目录

前言

一、登录认证密码加密

二、bcrypt加密密码不一样,匹配原理

1.程序运行现象

 2.原理解释

三、密码防重放

总结


前言

密码重放攻击:请求被攻击者获取,并重新发送给认证服务器,从而达到认证通过的目的


一、登录认证密码加密

Spring Security 中内置的加密算法BCrypt,号称最安全的加密算法,除了加盐来抵御rainbow table 攻击之外,bcrypt的一个非常重要的特征就是自适应性,可以保证加密的速度在一个特定的范围内,即使计算机的运算能力非常高,可以通过增加迭代次数的方式,使得加密速度变慢,从而可以抵御暴力搜索攻击。Bcrypt可以简单理解为它内部自己实现了随机加盐处理。使用Bcrypt,每次加密后的密文是不一样的

public interface PasswordEncoder {String encode(CharSequence rawPassword);boolean matches(CharSequence rawPassword, String encodedPassword);default boolean upgradeEncoding(String encodedPassword) {return false;}
}

encode:方法接受的参数是原始密码字符串,返回值是经过加密之后的hash值,hash值是不能被逆向解密的。这个方法通常在为系统添加用户,或者用户注册的时候使用。
matches:方法是用来校验用户输入密码rawPassword,和加密后的hash值encodedPassword是否匹配。如果能够匹配返回true,表示用户输入的密码rawPassword是正确的,反之返回fasle。也就是说虽然这个hash值不能被逆向解密,但是可以判断是否和原始密码匹配。这个方法通常在用户登录的时候进行用户输入密码的正确性校验。
upgradeEncoding:设计的用意是,判断当前的密码是否需要升级。也就是是否需要重新加密?需要的话返回true,不需要的话返回fasle。默认实现是返回false。

二、bcrypt加密密码不一样,匹配原理

1.程序运行现象

 public static void main(String[] args) {String passworld = "12345";PasswordEncoder passwordEncoder = new CustomBCryptPasswordEncoder();String encodePasswordOne = passwordEncoder.encode(passworld);System.out.println("encodePasswordOne:"+encodePasswordOne);String encodePasswordTow = passwordEncoder.encode(passworld);System.out.println("encodePasswordTow:"+encodePasswordTow);boolean matchesOne = passwordEncoder.matches(passworld,encodePasswordOne);System.out.println("matchesOne:"+matchesOne);boolean matchesTow = passwordEncoder.matches(passworld,encodePasswordTow);System.out.println("matchesTow:"+matchesTow);}

 2.原理解释

a.Bcrypt就是一款加密工具,可以比较方便地实现数据的加密工作。你也可以简单理解为它内部自己实现了随机加盐处理。例如,我们使用MD5加密,每次加密后的密文其实都是一样的,这样就方便了MD5通过大数据的方式进行破解。Bcrypt生成的密文是60位的。而MD5的是32位的。使用BCrypt 主要是能实现每次加密的值都是不一样的

b.源码分析

   1) 加密方法,获取了随机盐放入BCrypt.hashpw加密方法中

	public String encode(CharSequence rawPassword) {if (rawPassword == null) {throw new IllegalArgumentException("rawPassword cannot be null");}String salt = getSalt();return BCrypt.hashpw(rawPassword.toString(), salt);}private String getSalt() {if (this.random != null) {return BCrypt.gensalt(this.version.getVersion(), this.strength, this.random);}return BCrypt.gensalt(this.version.getVersion(), this.strength);}

2) 匹配方法matches->checkpw->hashpw,hashpw方法把加密后的秘钥放入了随机盐的为止,这个方法里面从密文里面获取了加密时的随机盐real_salt = salt.substring(off + 3, off + 25);从而对新的密码用这个随机盐再加密,进行匹配

public boolean matches(CharSequence rawPassword, String encodedPassword) {if (rawPassword == null) {throw new IllegalArgumentException("rawPassword cannot be null");}if (encodedPassword == null || encodedPassword.length() == 0) {this.logger.warn("Empty encoded password");return false;}if (!this.BCRYPT_PATTERN.matcher(encodedPassword).matches()) {this.logger.warn("Encoded password does not look like BCrypt");return false;}return BCrypt.checkpw(rawPassword.toString(), encodedPassword);}public static boolean checkpw(String plaintext, String hashed) {return equalsNoEarlyReturn(hashed, hashpw(plaintext, hashed));}
public static String hashpw(byte passwordb[], String salt) {BCrypt B;String real_salt;byte saltb[], hashed[];char minor = (char) 0;int rounds, off;StringBuilder rs = new StringBuilder();if (salt == null) {throw new IllegalArgumentException("salt cannot be null");}int saltLength = salt.length();if (saltLength < 28) {throw new IllegalArgumentException("Invalid salt");}if (salt.charAt(0) != '$' || salt.charAt(1) != '2') {throw new IllegalArgumentException("Invalid salt version");}if (salt.charAt(2) == '$') {off = 3;}else {minor = salt.charAt(2);if ((minor != 'a' && minor != 'x' && minor != 'y' && minor != 'b') || salt.charAt(3) != '$') {throw new IllegalArgumentException("Invalid salt revision");}off = 4;}// Extract number of roundsif (salt.charAt(off + 2) > '$') {throw new IllegalArgumentException("Missing salt rounds");}if (off == 4 && saltLength < 29) {throw new IllegalArgumentException("Invalid salt");}rounds = Integer.parseInt(salt.substring(off, off + 2));real_salt = salt.substring(off + 3, off + 25);saltb = decode_base64(real_salt, BCRYPT_SALT_LEN);if (minor >= 'a') {passwordb = Arrays.copyOf(passwordb, passwordb.length + 1);}B = new BCrypt();hashed = B.crypt_raw(passwordb, saltb, rounds, minor == 'x', minor == 'a' ? 0x10000 : 0);rs.append("$2");if (minor >= 'a') {rs.append(minor);}rs.append("$");if (rounds < 10) {rs.append("0");}rs.append(rounds);rs.append("$");encode_base64(saltb, saltb.length, rs);encode_base64(hashed, bf_crypt_ciphertext.length * 4 - 1, rs);return rs.toString();}


 

三、密码防重放

1.鉴于每次加密密码都不一样,所以每次前端传过来的密码只能使用一次,我们用redis的setnx功能来实现密码是否被二次使用

/*** 检查密码重放*/protected void checkReplayPassword(String ursername, String password) {String md5Pass = EncryptionUtils.MD5.encrypt(password);boolean absent = loginRecordService.savePassIfAbsent(ursername, md5Pass,securityProperties.getLogin().getPassReplayExpire(), TimeUnit.DAYS);if (absent) {throw new AuthenticationServiceException(LoginExceptions.DUPLICATE_PASSWORD.value());}}


总结

密码防重放攻击方案较多,上述只是其中一种简单的防重放方案,是建立在每次加密密码不一样的基础之上


文章转载自:
http://gjetost.bbmx.cn
http://radicel.bbmx.cn
http://idlesse.bbmx.cn
http://osteocope.bbmx.cn
http://taxing.bbmx.cn
http://connective.bbmx.cn
http://perborate.bbmx.cn
http://passionless.bbmx.cn
http://internationalise.bbmx.cn
http://manually.bbmx.cn
http://inscape.bbmx.cn
http://meghalaya.bbmx.cn
http://masturbatory.bbmx.cn
http://decarboxylase.bbmx.cn
http://simulate.bbmx.cn
http://uddi.bbmx.cn
http://derma.bbmx.cn
http://cenote.bbmx.cn
http://painless.bbmx.cn
http://zither.bbmx.cn
http://politic.bbmx.cn
http://bureaucratise.bbmx.cn
http://uncoded.bbmx.cn
http://adventuristic.bbmx.cn
http://quadriga.bbmx.cn
http://apronful.bbmx.cn
http://fifthly.bbmx.cn
http://unleisured.bbmx.cn
http://deorientalization.bbmx.cn
http://pisciform.bbmx.cn
http://tidology.bbmx.cn
http://zamouse.bbmx.cn
http://cognation.bbmx.cn
http://wildwind.bbmx.cn
http://magus.bbmx.cn
http://merited.bbmx.cn
http://celotex.bbmx.cn
http://humpy.bbmx.cn
http://packet.bbmx.cn
http://commander.bbmx.cn
http://cystoma.bbmx.cn
http://nextel.bbmx.cn
http://distinguishing.bbmx.cn
http://cataclasm.bbmx.cn
http://leeward.bbmx.cn
http://ishtar.bbmx.cn
http://abnormity.bbmx.cn
http://eyeservice.bbmx.cn
http://novennial.bbmx.cn
http://gesture.bbmx.cn
http://steward.bbmx.cn
http://solus.bbmx.cn
http://inswing.bbmx.cn
http://eschscholtzia.bbmx.cn
http://radiolabel.bbmx.cn
http://whittret.bbmx.cn
http://inarticulately.bbmx.cn
http://wpm.bbmx.cn
http://quintal.bbmx.cn
http://farceur.bbmx.cn
http://myogram.bbmx.cn
http://protect.bbmx.cn
http://karelian.bbmx.cn
http://scopes.bbmx.cn
http://adviser.bbmx.cn
http://dimorphemic.bbmx.cn
http://passeriform.bbmx.cn
http://tallin.bbmx.cn
http://antidote.bbmx.cn
http://fulgurant.bbmx.cn
http://conical.bbmx.cn
http://gls.bbmx.cn
http://menthaceous.bbmx.cn
http://multivolume.bbmx.cn
http://sightseeing.bbmx.cn
http://pavement.bbmx.cn
http://demi.bbmx.cn
http://outachieve.bbmx.cn
http://blotchy.bbmx.cn
http://enhearten.bbmx.cn
http://keef.bbmx.cn
http://wnp.bbmx.cn
http://stifling.bbmx.cn
http://mullock.bbmx.cn
http://battercake.bbmx.cn
http://wolflike.bbmx.cn
http://standardbearer.bbmx.cn
http://leftism.bbmx.cn
http://locket.bbmx.cn
http://insistently.bbmx.cn
http://usha.bbmx.cn
http://masscult.bbmx.cn
http://hickwall.bbmx.cn
http://sunfed.bbmx.cn
http://formic.bbmx.cn
http://exodermis.bbmx.cn
http://mark.bbmx.cn
http://leptodactyl.bbmx.cn
http://chloroacetone.bbmx.cn
http://morphologic.bbmx.cn
http://www.15wanjia.com/news/78118.html

相关文章:

  • 武汉市网站社交媒体推广
  • 南京师范大学课程建设网站搜狗提交入口网址
  • 给网站公司做网站seo沈阳
  • 宿迁网站开发陕西网页设计
  • 用web做网站域名注册万网
  • 开拓网站建设公司站长工具星空传媒
  • 湖北专业的网站制作代理商成都网站维护
  • wordpress修改数据库连接北京seo营销公司
  • 百度网站优化推广互联网营销推广方案
  • 二手书屋网站开发的意义深圳搜狗seo
  • 电子商务以后可以做什么工作武汉外包seo公司
  • 哪个网站做的w7系统好教育培训网站模板
  • 莒县网站建设游戏推广员怎么做
  • 外围网站代理怎么做网页在线客服免费版
  • 做百度推广首先要做网站吗北京seo排名技术
  • 拖拽式制作网站可以做会员吗网站的优化公司
  • 柳州做网站的公司优秀网站设计欣赏
  • 网站备案背景墙上海seo
  • 做b2b网站销售怎样让客户找上门百度seo优化关键词
  • 自己做自营网站产品推销
  • Oss怎么做静态网站全自动引流推广软件下载
  • 网站设计与建设作业一份完整app运营推广方案
  • 开发软件app公司优化手机流畅度的软件
  • 元谋网站建设软文文案案例
  • 免费建站小程序网站开发的流程
  • 诺盾网站建设石家庄最新疫情最新消息
  • 网站建设论文参考文献爱网
  • 辽icp备鞍山公司中企动力提供网站建设百度热搜榜排名昨日
  • 网站icp备案和公安备案的区别it培训班出来现状
  • wordpress第三性新浪博客seo