1
0
Fork 0
mirror of https://github.com/Luzifer/go-openssl.git synced 2024-12-20 19:01:18 +00:00
go-openssl/examples_test.go

37 lines
842 B
Go
Raw Normal View History

2015-07-17 21:49:39 +00:00
package openssl
import "fmt"
// #nosec G101 -- Contains harcoded test passphrase
func ExampleOpenSSL_EncryptBytes() {
2015-07-17 21:49:39 +00:00
plaintext := "Hello World!"
passphrase := "z4yH36a6zerhfE5427ZV"
o := New()
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))
}
// #nosec G101 -- Contains harcoded test passphrase
func ExampleOpenSSL_DecryptBytes() {
2015-07-17 21:49:39 +00:00
opensslEncrypted := "U2FsdGVkX19ZM5qQJGe/d5A/4pccgH+arBGTp+QnWPU="
passphrase := "z4yH36a6zerhfE5427ZV"
o := New()
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
}