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
+26k Golang : Convert IP address string to long ( unsigned 32-bit integer )
+7k Web : How to see your website from different countries?
+13.2k Golang : Convert(cast) int to int64
+14.8k Golang : Find commonalities in two slices or arrays example
+15.6k Golang : rune literal not terminated error
+7.5k Golang : Create zip/ePub file without compression(use Store algorithm)
+6.1k Golang : Measure execution time for a function
+6k Fontello : How to load and use fonts?
+5.4k Unix/Linux : How to archive and compress entire directory ?
+8.1k Golang : Randomize letters from a string example
+9k Golang : Inject/embed Javascript before sending out to browser example
+5k Golang : Calculate a pip value and distance to target profit example