Converting byte array to hex format

Asked by At

I am hashing passwords using Sha256.Sum256 then I'm supposed to store the hashed password on the database, but what I get instead is a byte array instead of a hex value. I cannot do ("%x", hash) because that only works on fmt

1 Answers

Vorsprung On

I think what you are asking is "how do I make a string of the hexadecimal representation of the byte array"

package main

import (

func main() {
    password := "abc123"
    sum := sha256.Sum256([]byte(password))
    hexstring := fmt.Sprintf("%x", sum)