Golang crypto/x509.MarshalPKIXPublicKey function example
package crypto/x509
MarshalPKIXPublicKey serialises a public key to DER-encoded PKIX format.
Golang crypto/x509.MarshalPKIXPublicKey function usage example
package main
import (
"crypto/rsa"
"crypto/sha256"
"crypto/rand"
"crypto/x509"
"os"
"fmt"
"encoding/hex"
)
func main() {
privatekey, err := rsa.GenerateKey(rand.Reader, 1024)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
var publickey rsa.PublicKey
publickey = privatekey.PublicKey
der, err := x509.MarshalPKIXPublicKey(&publickey)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
var fp [sha256.Size]byte
fp = sha256.Sum256(der)
fmt.Printf("%s\n", hex.EncodeToString(fp[:8]))
}
Reference :
Advertisement
Something interesting
Tutorials
+11.1k Golang : Fix go.exe is not compatible with the version of Windows you're running
+7k Golang : How to call function inside template with template.FuncMap
+8.3k Golang : Oanda bot with Telegram and RSI example
+7.7k Golang : get the current working directory of a running program
+9.3k Golang : Generate random Chinese, Japanese, Korean and other runes
+9.3k Golang : Temperatures conversion example
+6.8k Golang : Find the longest line of text example
+80.6k Golang : How to return HTTP status code?
+12.5k Golang : Forwarding a local port to a remote server example
+10.1k Golang : Edge detection with Sobel method
+35.1k Golang : Upload and download file to/from AWS S3
+48.1k Golang : How to convert JSON string to map and slice