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
+38.1k Golang : Read a text file and replace certain words
+12.1k Golang : Sort and reverse sort a slice of runes
+18.3k Golang : Get path name to current directory or folder
+14.4k Golang : Parsing or breaking down URL
+10k Golang : Convert octal value to string to deal with leading zero problem
+5k Python : Find out the variable type and determine the type with simple test
+10.2k Golang : Bcrypting password
+13.6k Golang : Query string with space symbol %20 in between
+13.7k Android Studio : Password input and reveal password example
+18.1k Golang : Check if a directory exist or not
+14.2k Golang : Check if a file exist or not
+12.3k Golang : Get month name from date example