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 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办