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
+6.6k Golang : Gorrila set route name and get the current route name
+27.8k Golang : Save map/struct to JSON or XML file
+5.7k PHP : Shuffle to display different content or advertisement
+6.3k Golang : Dealing with postal or zip code example
+8.5k Golang : Qt get screen resolution and display on center example
+11.7k Golang : Pass database connection to function called from another package and HTTP Handler
+7.7k Golang : Executing and evaluating nested loop in html template
+22.9k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+9.4k Golang : Generate random integer or float number
+7.7k Linux/Unix : fatal: the Postfix mail system is already running
+8.3k Golang : Find correlation coefficient example
+11.8k Generate salted password with OpenSSL example