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
+13.3k Android Studio : Password input and reveal password example
+8.5k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+4.2k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+6.4k Grep : How to grep for strings inside binary data
+4.7k HTTP common errors and their meaning explained
+21.4k Golang : GORM create record or insert new record into database example
+6.7k Get Facebook friends working in same company
+13.3k Golang : Count number of runes in string
+10.7k Golang : Get UDP client IP address and differentiate clients by port number
+5.6k Swift : Get substring with rangeOfString() function example
+17.4k Golang : Find smallest number in array