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.8k Swift : Convert (cast) String to Double
+7.4k Golang : On lambda, anonymous, inline functions and function literals
+17.8k Golang : How to make function callback or pass value from function as parameter?
+7k Findstr command the Grep equivalent for Windows
+12k Golang : How to get a user home directory path?
+18.5k Android Studio : AlertDialog and EditText to get user string input example
+7.3k Golang : Convert word to its plural form example
+4.5k Golang : Shortening import identifier
+8.1k Golang : Detect number of active displays and the display's resolution
+25.5k Golang : How to check if a connection to database is still alive ?
+8.8k Golang : Test a slice of integers for odd and even numbers
+4.4k PHP : Hide PHP version information from curl