2015-07-17 21:49:39 +00:00
|
|
|
package openssl
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
2018-11-02 11:44:45 +00:00
|
|
|
func ExampleOpenSSL_EncryptBytes() {
|
2015-07-17 21:49:39 +00:00
|
|
|
plaintext := "Hello World!"
|
|
|
|
passphrase := "z4yH36a6zerhfE5427ZV"
|
|
|
|
|
|
|
|
o := New()
|
|
|
|
|
2020-06-13 13:29:46 +00:00
|
|
|
enc, err := o.EncryptBytes(passphrase, []byte(plaintext), PBKDF2SHA256)
|
2015-07-17 21:49:39 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("An error occurred: %s\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Encrypted text: %s\n", string(enc))
|
|
|
|
}
|
|
|
|
|
2018-11-02 11:44:45 +00:00
|
|
|
func ExampleOpenSSL_DecryptBytes() {
|
2015-07-17 21:49:39 +00:00
|
|
|
opensslEncrypted := "U2FsdGVkX19ZM5qQJGe/d5A/4pccgH+arBGTp+QnWPU="
|
|
|
|
passphrase := "z4yH36a6zerhfE5427ZV"
|
|
|
|
|
|
|
|
o := New()
|
|
|
|
|
2020-06-13 13:29:46 +00:00
|
|
|
dec, err := o.DecryptBytes(passphrase, []byte(opensslEncrypted), BytesToKeyMD5)
|
2015-07-17 21:49:39 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("An error occurred: %s\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Decrypted text: %s\n", string(dec))
|
|
|
|
|
|
|
|
// Output:
|
|
|
|
// Decrypted text: hallowelt
|
|
|
|
}
|