我在node.js 中有一个身份验证逻辑var crypto = require('crypto');var SaltLength = 9;function createHash(password) { var salt = generateSalt(SaltLength); var hash = md5(password + salt); return salt + hash;}function validateHash(hash, password) { var salt = hash.substr(0, SaltLength); var validHash = salt + md5(password + salt); return hash === validHash;}function generateSalt(len) { var set = '0123456789abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ', setLen = set.length, salt = ''; for (var i = 0; i < len; i++) { var p = Math.floor(Math.random() * setLen); salt += set[p]; } return salt;}function md5(string) { return crypto.createHash('md5').update(string).digest('hex');}如何将其移植到Go?
1 回答
- 1 回答
- 0 关注
- 231 浏览
添加回答
举报
0/150
提交
取消