douji8017 2018-03-22 19:55
浏览 1099
已采纳

为什么bcrypt库的CompareHashAndPassword方法很慢?

I want to compare password and use bcrypt library but CompareHashAndPassword method is very slow. Why this method is slow?

var b  []byte =  []byte("1234")
 var bx  []byte =  []byte("$2a$14$RWV9NhWmlQmSoV9toM/k9OIzaNcYssCiauPVAljiX2NGhqvyxcOMy")
 fmt.Println("Start Compare: ", time.Now().Format("2006-01-02 15:04:05.000000"))
 err := bcrypt.CompareHashAndPassword(bx, b)
 fmt.Println("Completed Compare: ", time.Now().Format("2006-01-02 15:04:05.000000"))
 fmt.Println("------------------------")

Result:

Start Compare: 2018-03-22 22:53:09.142380

Completed Compare: 2018-03-22 22:53:10.347585

Can you help me?

  • 写回答

1条回答 默认 最新

  • drug95107 2018-03-22 20:07
    关注

    Slowness is a design feature of bcrypt, because if it was fast, it would be easy to brute-force password hashes. From Wikipedia:

    Besides incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive function: over time, the iteration count can be increased to make it slower, so it remains resistant to brute-force search attacks even with increasing computation power.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊