Created
May 8, 2020 07:18
-
-
Save yukithm/eada4c7f7ab581d83c2067cfc25ce020 to your computer and use it in GitHub Desktop.
ハッシュ値の文字列長(Hex, Base64) https://play.golang.org/p/LQAUgxzAaIh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/md5" | |
"crypto/sha1" | |
"crypto/sha256" | |
"crypto/sha512" | |
"encoding/base64" | |
"encoding/hex" | |
"fmt" | |
"hash" | |
"github.com/google/uuid" | |
"golang.org/x/crypto/sha3" | |
) | |
func main() { | |
printHash("MD5", md5.New()) | |
printHash("SHA-1", sha1.New()) | |
printHash("SHA-224", sha256.New224()) | |
printHash("SHA-256", sha256.New()) | |
printHash("SHA-384", sha512.New384()) | |
printHash("SHA-512", sha512.New()) | |
printHash("SHA-512/224", sha512.New512_224()) | |
printHash("SHA-512/256", sha512.New512_256()) | |
printHash("SHA3-224", sha3.New224()) | |
printHash("SHA3-256", sha3.New256()) | |
printHash("SHA3-384", sha3.New384()) | |
printHash("SHA3-512", sha3.New512()) | |
uuidStr := uuid.Must(uuid.NewRandom()).String() | |
fmt.Printf("%21s (%3d): %s\n", "UUIDv4", len(uuidStr), uuidStr) | |
} | |
func printHash(name string, f hash.Hash) { | |
printHashBytes(name, f.Sum(nil)) | |
} | |
func printHashBytes(name string, data []byte) { | |
hexStr := hex.EncodeToString(data) | |
fmt.Printf("%16s (hex, %3d): %s\n", name, len(hexStr), hexStr) | |
b64Str := base64.RawURLEncoding.EncodeToString(data) | |
fmt.Printf("%16s (b64, %3d): %s\n", name, len(b64Str), b64Str) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment