duanfen7676 2016-07-06 00:32
浏览 98
已采纳

golang bcrypt返回的字节数

I am using the Golang Bcrypt algorithm and it returns in bytes for instance

password := []byte("MyPassword")

hashedPassword, err := bcrypt.GenerateFromPassword(password, 12)

That code above returns a hashPassword of

[36 50 97 36 49 50 36 103 118 90 90 104 82 114 99 88 113 81 46 48 69 52 105 51 82 71 53 104 101 83 79 107 80 110 53 103 53 99 84 110 97 99 82 106 56 68 66 54 84 89 83 107 100 108 87 67 115 57 77 97] My question is; is that as save as the string implementation that I've used in Java and C# where the Hashpassword would be return in strings,numerals and other characters ? I have got the code and testing it from https://godoc.org/golang.org/x/crypto/bcrypt#CompareHashAndPassword .

  • 写回答

1条回答 默认 最新

  • doulan0297 2016-07-06 00:56
    关注

    Yes, bcrypt's functions do operate on byte slices, however, the returned hash is base64 encoded. A string representation of the hashed password can therefore be obtained by doing a string conversion:

    hashedPasswordStr := string(hashedPassword)
    

    This question provides some reasons why arrays are preferred for storing passwords over strings (different language, but same principles).

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

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)