Golang crypto/x509.DecryptPEMBlock function example
package crypto/x509
DecryptPEMBlock takes a password encrypted PEM block and the password used to encrypt it and returns a slice of decrypted DER encoded bytes. It inspects the DEK-Info header to determine the algorithm used for decryption. If no DEK-Info header is present, an error is returned. If an incorrect password is detected an IncorrectPasswordError is returned.
Golang crypto/x509.DecryptPEMBlock function usage example
blockType := "RSA PRIVATE KEY"
password := []byte("password")
// see http://golang.org/pkg/crypto/x509/#pkg-constants
cipherType := x509.PEMCipherAES256
EncryptedPEMBlock, err := x509.EncryptPEMBlock(rand.Reader,
blockType,
[]byte("secret message"),
password,
cipherType)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
DecryptedPEMBlock, err := x509.DecryptPEMBlock(EncryptedPEMBlock, password)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
See https://www.socketloop.com/tutorials/golang-encrypt-and-decrypt-data-with-x509-crypto
Reference :
See also : Golang crypto/x509.EncryptPEMBlock function example
Advertisement
Something interesting
Tutorials
+10.1k Golang : Edge detection with Sobel method
+17.8k Golang : Iterate linked list example
+29.3k Golang : Save map/struct to JSON or XML file
+5.2k Golang : Customize scanner.Scanner to treat dash as part of identifier
+8.2k Prevent Write failed: Broken pipe problem during ssh session with screen command
+6.2k Golang : Calculate US Dollar Index (DXY)
+11.9k Golang : Convert decimal number(integer) to IPv4 address
+6.3k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+16.5k Golang : File path independent of Operating System
+17.2k Golang : Find file size(disk usage) with filepath.Walk
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format
+41k Golang : How to check if a string contains another sub-string?