Skip to content

Instantly share code, notes, and snippets.

@nordineb
Last active October 30, 2023 19:35
Show Gist options
  • Save nordineb/719d7e5d48dce04e339fde350634a1a4 to your computer and use it in GitHub Desktop.
Save nordineb/719d7e5d48dce04e339fde350634a1a4 to your computer and use it in GitHub Desktop.
SHA512 digest

sha512 digest

Bash

echo -n 12345678900 | openssl dgst -binary -sha512 | base64

Go

package main

import (
	"crypto/sha512"
	"encoding/base64"
	"fmt"
)

func hash(ssn string) string {
	h := sha512.Sum512([]byte(ssn))
	return "{SHA256}" + base64.StdEncoding.EncodeToString(h[:])
}

func main() {
	fmt.Println(hash("12345678900"))
}

python

import base64
import hashlib

input = "12345678900"

digest = hashlib.sha512(str.encode(input)).digest()
digest_base64 = base64.b64encode(digest).decode('utf-8')

print (digest_base64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment