Golang crypto/x509.EncryptPEMBlock function example
package crypto/x509
EncryptPEMBlock returns a PEM block of the specified type holding the given DER-encoded data encrypted with the specified algorithm and password.
Golang crypto/x509.EncryptPEMBlock 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)
}
See https://www.socketloop.com/tutorials/golang-encrypt-and-decrypt-data-with-x509-crypto
Reference :
See also : Golang crypto/x509.DecryptPEMBlock function example
Advertisement
Something interesting
Tutorials
+7.3k Golang : Of hash table and hash map
+13k Golang : Get terminal width and height example
+6.9k Golang : Calculate BMI and risk category
+8.1k Golang : HTTP Server Example
+9.7k Golang : Detect number of active displays and the display's resolution
+18k Golang : Check if a directory exist or not
+20.2k Golang : Determine if directory is empty with os.File.Readdir() function
+7.4k Golang : Scanf function weird error in Windows
+6.5k Elasticsearch : Shutdown a local node
+10.8k Golang : Natural string sorting example
+19k Golang : Padding data for encryption and un-padding data for decryption
+18.8k Golang : How to make function callback or pass value from function as parameter?