Hello crypto

Comment

Author: Admin | 2025-04-28

Sha512 = sha512.New() pwdByte = append(pwdByte, salt...) sha512.Write(pwdByte) // Get the SHA-512 hashed password var hashedPassword = sha512.Sum(nil) // Convert the hashed to hex string var hashedPasswordHex = hex.EncodeToString(hashedPassword) return hashedPasswordHex}// Check if two passwords matchfunc doPasswordsMatch(hashedPassword, currPassword string, salt []byte) bool { var currPasswordHash = hashFunc(currPassword, salt) return hashedPassword == currPasswordHash}func main() { var salt = generateSalt(saltSize) // Hash password var hashedPassword = hashFunc("Hello GoLinuxcloud", salt) fmt.Println("Salt:", salt) fmt.Println("Hased Password:", hashedPassword) // Check if hashed password match original string fmt.Println("check hashed passwor with ", "hello", ":", doPasswordsMatch(hashedPassword, "hello", salt)) fmt.Println("check hashed passwor with ", "Hello GoLinuxcloud", ":", doPasswordsMatch(hashedPassword, "Hello GoLinuxcloud", salt))}Output:Salt: [37 134 147 225 191 181 103 195 185 185 142 69 247 240 106 188]Hased Password: 80f770d6991883e26ca4286dbc3fd9cad83ef3eea933d70ef15e42335d6a7a97e67d18b1a753e0f397179bcf5ca025575d123c24aecfeee22eae938050b4324dcheck hashed passwor with hello : falsecheck hashed passwor with Hello GoLinuxcloud : trueSummaryHere are some examples of using sha512 in Golang. Noted that SHA512 is a hash algorithm based on non-linear functions, so it is impossible to decryption method and so is made to be uncrackable.Referenceshttps://en.bitcoinwiki.org/wiki/SHA-512https://en.wikipedia.org/wiki/SHA-2https://pkg.go.dev/crypto/sha512https://en.wikipedia.org/wiki/Checksumhttps://en.wikipedia.org/wiki/Salt_(cryptography) Can't find what you're searching for? Let us assist you. Enter your query below, and we'll provide instant results tailored to your needs.

Add Comment