当前位置:网站首页>Golang MD5 encryption and MD5 salt value encryption
Golang MD5 encryption and MD5 salt value encryption
2022-07-02 15:42:00 【sweey_ lff】
1.MD5 encryption
1)MD5 package :"crypto/md5"
2) Realization
func genMd5(code string) string{
//c1 := md5.Sum([]byte(code)) // return [16]byte Array
Md5 := md5.New()
_, _ = io.WriteString(Md5, code)
return hex.EncodeToString(Md5.Sum(nil))
}2. MD5 Salt value encryption
We can use github A library written by others :https://github.com/anaskhan96/go-password-encoder
1) Import package :
go get github.com/anaskhan96/go-password-encoder2) Specific usage :
package main
import (
"crypto/md5"
"fmt"
"github.com/anaskhan96/go-password-encoder"
)
func main() {
// Mode one : Use default options
salt, encodedPwd := password.Encode("generic password", nil)
check := password.Verify("generic password", salt, encodedPwd, nil)
fmt.Println(check) // true
// Mode two : Use custom options
options := &password.Options{10, 10000, 50, md5.New}
salt, encodedPwd = password.Encode("generic password", options)
check = password.Verify("generic password", salt, encodedPwd, options)
fmt.Println(check) // true
} The Options Structure is used to enable custom options :
type Options struct {
SaltLen int
Iterations int
KeyLen int
HashFunction func() hash.Hash
}SaltLen:User generated length , Default 256- Iterations: PBKDF2 The number of iterations in the function , Default 10000
- KeyLen:BKDF2 Length of encoding key in function , Default 512
- HashFunction: Hash algorithm used , Default sha512
边栏推荐
- 6096. 咒语和药水的成功对数
- Evaluation of embedded rz/g2l processor core board and development board of Feiling
- Thoroughly understand browser strong cache and negotiation cache
- Name of institution approved in advance
- 02. After containerization, you must face golang
- 03.golang初步使用
- 【LeetCode】1905-统计子岛屿
- Fiddler实现手机抓包——入门
- Storage read-write speed and network measurement based on rz/g2l | ok-g2ld-c development board
- Jsp+mysql006 community management system
猜你喜欢

怎样从微信返回的json字符串中截取某个key的值?
![[leetcode] 1254 - count the number of closed Islands](/img/84/f888ae0e164951cd9623fb3bf4a984.png)
[leetcode] 1254 - count the number of closed Islands

Steps for Navicat to create a new database

(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice

Deux séquences ergodiques connues pour construire des arbres binaires

Beijing rental data analysis

【LeetCode】417-太平洋大西洋水流问题
![[salesforce] how to confirm your salesforce version?](/img/ce/4c844b1b686397faa1b6aa3d57e034.png)
[salesforce] how to confirm your salesforce version?

Thoroughly understand browser strong cache and negotiation cache

爱可可AI前沿推介(7.2)
随机推荐
Two traversal sequences are known to construct binary trees
03.golang初步使用
【LeetCode】876-链表的中间结点
6091. 划分数组使最大差为 K
LeetCode刷题——去除重复字母#316#Medium
[leetcode] 1254 - count the number of closed Islands
Force deduction solution summarizes the lucky numbers in 1380 matrix
[leetcode] 344 reverse string
6095. Strong password checker II
SQL修改语句
高考录取分数线爬取
XPT2046 四线电阻式触摸屏
(5) Flink's table API and SQL update mode and Kafka connector case
2278. 字母在字符串中的百分比
Build your own semantic segmentation platform deeplabv3+
C # get PLC information (kepserver) II
For the problem that Folium map cannot be displayed, the temporary solution is as follows
怎样从微信返回的json字符串中截取某个key的值?
Leetcode skimming -- incremental ternary subsequence 334 medium
LeetCode刷题——统计各位数字都不同的数字个数#357#Medium