Created
January 25, 2024 04:10
-
-
Save arvin243/73c5011bc4a0fb44b836cd7670a0faf8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/sha256" | |
"fmt" | |
"math/rand" | |
"strconv" | |
) | |
func main() { | |
// salt is random int from 0~10000 | |
salt := rand.Int63n(10000) | |
password := "hello123" | |
encryptedPassword := encrypt(password, salt) | |
fmt.Printf("encrypted password=%s, len=%d\n", encryptedPassword) | |
} | |
func encrypt(password string, salt int64) string { | |
sum := sha256.Sum256([]byte(password + strconv.FormatInt(salt, 10))) | |
return fmt.Sprintf("%x", sum) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment