MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / CalcCachingSha2Password

Function CalcCachingSha2Password

IceFireDB-SQLProxy/pkg/mysql/mysql/util.go:54–79  ·  view source on GitHub ↗

CalcCachingSha2Password: Hash password using MySQL 8+ method (SHA256)

(scramble []byte, password string)

Source from the content-addressed store, hash-verified

52
53// CalcCachingSha2Password: Hash password using MySQL 8+ method (SHA256)
54func CalcCachingSha2Password(scramble []byte, password string) []byte {
55 if len(password) == 0 {
56 return nil
57 }
58
59 // XOR(SHA256(password), SHA256(SHA256(SHA256(password)), scramble))
60
61 crypt := sha256.New()
62 crypt.Write([]byte(password))
63 message1 := crypt.Sum(nil)
64
65 crypt.Reset()
66 crypt.Write(message1)
67 message1Hash := crypt.Sum(nil)
68
69 crypt.Reset()
70 crypt.Write(message1Hash)
71 crypt.Write(scramble)
72 message2 := crypt.Sum(nil)
73
74 for i := range message1 {
75 message1[i] ^= message2[i]
76 }
77
78 return message1
79}
80
81func EncryptPassword(password string, seed []byte, pub *rsa.PublicKey) ([]byte, error) {
82 plain := make([]byte, len(password)+1)

Callers 2

genAuthResponseMethod · 0.50

Calls 1

ResetMethod · 0.45

Tested by

no test coverage detected