Created
June 8, 2020 20:40
-
-
Save d4z3x/d6226b524fed429a480bffb3b8f472c8 to your computer and use it in GitHub Desktop.
some basic pem decode ways using the crypto interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func decodeBackToPEMWithName(fname string, pk crypto.PrivateKey) string { | |
pemPrivateFile, _ := os.Create(fname) | |
var pemPrivateBlock = &pem.Block{ | |
Type: "RSA PRIVATE KEY", | |
Bytes: x509.MarshalPKCS1PrivateKey(pk.(*rsa.PrivateKey)), | |
} | |
pem.Encode(pemPrivateFile, pemPrivateBlock) | |
pemPrivateFile.Close() | |
return string(pemPrivateBlock.Bytes) | |
} | |
func decodeBackToPEM(pk crypto.PrivateKey) string { | |
pemPrivateFile, _ := os.Create("DecryptBytes_priv.key") | |
var pemPrivateBlock = &pem.Block{ | |
Type: "RSA PRIVATE KEY", | |
Bytes: x509.MarshalPKCS1PrivateKey(pk.(*rsa.PrivateKey)), | |
} | |
pem.Encode(pemPrivateFile, pemPrivateBlock) | |
pemPrivateFile.Close() | |
return string(pemPrivateBlock.Bytes) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment