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
+9.3k Golang : How to check if a string with spaces in between is numeric?
+8.7k Golang : Set or add headers for many or different handlers
+9.3k Golang : Write multiple lines or divide string into multiple lines
+19.8k Golang : Get current URL example
+17.7k Golang : Clone with pointer and modify value
+6.9k Golang : Find the longest line of text example
+10.7k Golang : Select region of interest with mouse click and crop from image
+6.8k Golang : Calculate pivot points for a cross
+5.8k Fix yum-complete-transaction error
+22.5k Golang : Read directory content with filepath.Walk()
+29.6k Golang : Login(Authenticate) with Facebook example