Golang : Load DSA public key from file example
Continue from previous tutorial on generating DSA private and public key. For this tutorial, we will learn how to load a DSA public key file and process the information.
package main
import (
"crypto/dsa"
"encoding/gob"
"fmt"
"os"
)
func main() {
//load public key
pubKeyFile, err := os.Open("DSApublic.key")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
decoder := gob.NewDecoder(pubKeyFile)
var publickey dsa.PublicKey
err = decoder.Decode(&publickey)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
pubKeyFile.Close()
//fmt.Printf("Public key : \n%x\n", pubKeyFile)
fmt.Printf("Public key parameter P: %v\n", publickey.Parameters.P)
fmt.Printf("Public key parameter Q: %v\n", publickey.Parameters.Q)
fmt.Printf("Public key parameter G: %v\n", publickey.Parameters.G)
fmt.Printf("Public key Y: %v\n", publickey.Y)
}
Hope this helps. Happy coding!
See also : Golang : Generate DSA private, public key and PEM files example
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.7k Golang : automatically figure out array length(size) with three dots
+22.9k Golang : Print out struct values in string format
+5.5k Unix/Linux : Get reboot history or check when was the last reboot date
+5k Golang : Generate Interleaved 2 inch by 5 inch barcode
+3k Golang : Fix go-cron set time not working issue
+21.4k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+12.6k Python : Convert IPv6 address to decimal and back to IPv6
+13.1k Golang : Increment string example
+11.9k Golang : Print UTF-8 fonts on image example
+6.8k Golang : A simple forex opportunities scanner
+20.4k Golang : Convert date string to variants of time.Time type examples