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 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛