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
+27.8k Golang : How to create new XML file ?
+11k Golang : Encrypt and decrypt data with x509 crypto
+9.3k JavaScript/JQuery : Detect or intercept enter key pressed example
+3.7k MariaDB/MySQL : How to get version information
+7.8k Golang : Heap sort example
+26.8k Golang : Connect to database (MySQL/MariaDB) server
+4.9k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+6.3k Golang : Calculate how many weeks left to go in a given year
+3.8k Golang : Experimental Jawi programming language
+11.4k Golang : zlib compress file example
+5.1k Golang : Scan forex opportunities by Bollinger bands
+16.6k Golang : Get all upper case or lower case characters from string example