I want to hash the password using go. the code below is from Rog's post. He's using sha1, it works. the part that is commented out is my code, i want to make it more secure using sha256
i am getting following error message.
I dont understand why Rog's code works, but not mine.
package main
import(
"crypto/rand"
"crypto/sha1"
//"crypto/sha256"
"fmt"
"io"
)
const SaltSize = 16
/*
func saltedHash(secret []byte) []byte {
fmt.Println("sha256 size: %v\n", sha256.Size)
buf := make([]byte, SaltSize, SaltSize + sha256.Size)
_, err := io.ReadFull(rand.Reader, buf)
if err != nil {
panic(fmt.Errorf("random read failed: %v", err))
}
h := sha256.New()
h.Write(buf)
h.Write(secret)
return h.Sum256(buf)
}
*/
func saltedHash1(secret []byte) []byte {
fmt.Println("sha1 size: %v\n", sha1.Size)
buf := make([]byte, SaltSize, SaltSize + sha1.Size)
_, err := io.ReadFull(rand.Reader, buf)
if err != nil {
panic(fmt.Errorf("random read failed: %v", err))
}
h := sha1.New()
h.Write(buf)
h.Write(secret)
return h.Sum(buf)
}
func main(){
//h := saltedHash([]byte("hello"))
//fmt.Println(h)
h1 := saltedHash1([]byte("hello"))
fmt.Println(h1)
}