Golang crypto/x509.MarshalPKCS1PrivateKey function example
package crypto/x509
MarshalPKCS1PrivateKey converts a private key to ASN.1 DER encoded form.
Golang crypto/x509.MarshalPKCS1PrivateKey function usage example
package main
import (
"fmt"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"os"
)
func main() {
privatekey, err := rsa.GenerateKey(rand.Reader, 1024)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
var marshalledPKCS1privkey []byte
marshalledPKCS1privkey = x509.MarshalPKCS1PrivateKey(privatekey)
// ASN.1 DER encoded form
pemBlock := pem.Block{
Type : "RSA PRIVATE KEY",
Headers : nil,
Bytes : marshalledPKCS1privkey,
}
fmt.Printf("%v\n", pemBlock)
}
Reference :
https://www.socketloop.com/tutorials/golang-example-for-rsa-package-functions-example
Advertisement
Something interesting
Tutorials
+5.6k Fix fatal error: evacuation not done in time problem
+7k Golang : Find the shortest line of text example
+6.2k Golang : Calculate US Dollar Index (DXY)
+4.7k Unix/Linux : How to pipe/save output of a command to file?
+19.1k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+25.7k Golang : missing Mercurial command
+30k Golang : Get time.Duration in year, month, week or day
+6.6k Golang : Totalize or add-up an array or slice example
+4.7k Javascript : Access JSON data example
+5.6k PHP : Convert CSV to JSON with YQL example
+21.7k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+15.6k Golang : Validate hostname