This repository has been archived on 2026-09-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
2026-09-07 13:08:39 +01:00
|
|
|
> [!IMPORTANT]
|
|
|
|
|
> **This repository is archived and no longer maintained.**
|
|
|
|
|
>
|
|
|
|
|
> These functions are one-line wrappers around the standard library.
|
|
|
|
|
>
|
|
|
|
|
> **Use instead** — standard library:
|
|
|
|
|
> ```go
|
|
|
|
|
> import (
|
|
|
|
|
> "crypto/sha256"
|
|
|
|
|
> "fmt"
|
|
|
|
|
> )
|
|
|
|
|
>
|
|
|
|
|
> sum := fmt.Sprintf("%x", sha256.Sum256([]byte(value))) // hex-encoded SHA256
|
|
|
|
|
> ```
|
|
|
|
|
> Use `crypto/sha512` the same way for SHA512.
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2024-06-21 21:54:44 +01:00
|
|
|
# Go Hash
|
|
|
|
|
|
|
|
|
|
Simple wrapper functions which take arbitrary string input and return string hashes in hex encoding.
|
|
|
|
|
|
|
|
|
|
The author is aware that this package is somewhat perfunctory, but likes not having to think about the `crypto` packages.
|
|
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"github.com/annybs/go/hash"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
if len(os.Args) < 2 {
|
|
|
|
|
fmt.Println(errors.New("input required"))
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println(hash.SHA256(os.Args[1]))
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Execute `go run main.go "any test string you like"` to create SHA256 output.
|
|
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
2024-07-19 15:52:06 +01:00
|
|
|
See [LICENSE.md](./LICENSE.md)
|