Skip to content

Instantly share code, notes, and snippets.

@arvin243
Created January 25, 2024 04:10
Show Gist options
  • Save arvin243/73c5011bc4a0fb44b836cd7670a0faf8 to your computer and use it in GitHub Desktop.
Save arvin243/73c5011bc4a0fb44b836cd7670a0faf8 to your computer and use it in GitHub Desktop.
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