I just startet with golang and write a very small script, everything works except for sha224. Can someone explain me please why i get the error (in regards to my script)? i dont need this error fixed, i wanna understand it to prevent future errors from my side.
The error 49:12: undeclared name: sha224 indicates that i didnt declare something, but i cant find it because i did the same for all hashing algorythms.
Im not a programmer, nor a specialist in golang. Its about my first go program.
package main
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"encoding/hex"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "http://45.32.153.207/index2.php"
fmt.Printf("HTML code of %s ...
", url)
resp, err := http.Get(url)
if err != nil {
panic(err)
}
defer resp.Body.Close()
html, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Printf("%s
", html)
toHash := CToGoString(html[:])
fmt.Printf("%s
", GetMD5Hash(toHash))
fmt.Printf("%s
", GetSha1Hash(toHash))
fmt.Printf("%s
", GetSha224Hash(toHash))
fmt.Printf("%s
", GetSha256Hash(toHash))
fmt.Printf("%s
", GetSha512Hash(toHash))
}
func GetMD5Hash(text string) string {
hasher := md5.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
func GetSha1Hash(text string) string {
hasher := sha1.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
func GetSha224Hash(text string) string {
hasher := sha224.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
func GetSha256Hash(text string) string {
hasher := sha256.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
func GetSha512Hash(text string) string {
hasher := sha512.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
func CToGoString(c []byte) string {
n := -1
for i, b := range c {
if b == 0 {
break
}
n = i
}
return string(c[:n+1])
}