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.5k Golang : Format strings to SEO friendly URL example
+28.3k Golang : Get and Set User-Agent examples
+17.8k Golang : Get RGBA values of each image pixel
+8k Golang : Serving HTTP and Websocket from different ports in a program example
+12.3k Golang : Verify token from Google Authenticator App
+8.5k Golang : Copy map(hash table) example
+4.1k Golang : Constant and variable names in native language
+5.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+39.2k Golang : How to count duplicate items in slice/array?
+18k Golang : Check if directory exist and create if does not exist
+5.9k Golang : Decode XML data from RSS feed
+15.9k Golang : Check if IP address is version 4 or 6