当前位置:网站首页>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-encoder
2) 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
边栏推荐
猜你喜欢
XPT2046 四线电阻式触摸屏
[experience cloud] how to get the metadata of experience cloud in vscode
SQL transaction
Pytoch saves tensor to Mat file
二叉树前,中,后序遍历
Leetcode skimming -- count the number of numbers with different numbers 357 medium
03. Preliminary use of golang
5. Practice: jctree implements the annotation processor at compile time
[leetcode] 417 - Pacific Atlantic current problem
Loss function and positive and negative sample allocation: Yolo series
随机推荐
[leetcode] 283 move zero
2278. 字母在字符串中的百分比
使用FFmpeg命令行进行UDP、RTP推流(H264、TS),ffplay接收
[development environment] install Visual Studio Ultimate 2013 development environment (download software | install software | run software)
[network security] network asset collection
自定义异常
已知兩種遍曆序列構造二叉樹
[leetcode] 19 delete the penultimate node of the linked list
使用 percona 工具给 MySQL 表加字段中断后该如何操作
Basic knowledge of cryptography
Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
The task cannot be submitted after the installation of flick is completed
Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
Leetcode skimming -- sum of two integers 371 medium
2303. 计算应缴税款总额
6092. Replace elements in the array
密码学基础知识
2278. Percentage of letters in string
[leetcode] 977 square of ordered array
/bin/ld: 找不到 -lgssapi_krb5