Documentation
¶
Overview ¶
Example ¶
ctx, cancel := context.WithCancel(context.Background()) defer cancel() c, err := New(ctx, "base64key://smGbjm71Nxd1Ig5FS0wj9SlbzAIrnolCz9bQQ6uAhl4=") if err != nil { fmt.Println(err) return } defer c.Close() plainKey := make([]byte, 32) _, _ = rand.Read(plainKey) cypherKey, err := c.EncryptKey(ctx, plainKey) if err != nil { fmt.Println(err) return } plainText := "asdfghjklñqwertyuiozxcvbnm," cypherText, err := c.Encrypt(ctx, []byte(plainText), cypherKey) if err != nil { fmt.Println(err) return } result, err := c.Decrypt(ctx, cypherText, cypherKey) if err != nil { fmt.Println(err) return } if r := string(result); r != plainText { fmt.Printf("unexpected result: %s", r) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var OpenCensusViews = secrets.OpenCensusViews
Functions ¶
func Decrypt ¶
Example ¶
msg := "zxcvbnmasdfghjklqwertyuiop1234567890" passphrase := "some secret" cypherMsg1, err := Encrypt([]byte(msg), []byte(passphrase)) if err != nil { fmt.Println(err) return } cypherMsg2, err2 := Encrypt([]byte(msg), []byte(passphrase)) if err2 != nil { fmt.Println(err2) return } if string(cypherMsg1) == string(cypherMsg2) { fmt.Println("two executions with the same input shall not generate the same output") return } res1, err3 := Decrypt(cypherMsg1, []byte(passphrase)) if err != nil { fmt.Println(err3) return } res2, err4 := Decrypt(cypherMsg2, []byte(passphrase)) if err != nil { fmt.Println(err4) return } if string(res1) != string(res2) { fmt.Println("results are different:", string(res1), string(res2)) return }
Output:
func Encrypt ¶
Example ¶
msg := "zxcvbnmasdfghjklqwertyuiop1234567890" passphrase := "some secret" cypherMsg, err := Encrypt([]byte(msg), []byte(passphrase)) if err != nil { fmt.Println(err) return } cypherMsg2, err2 := Encrypt([]byte(msg), []byte(passphrase)) if err2 != nil { fmt.Println(err2) return } if string(cypherMsg) == string(cypherMsg2) { fmt.Println("two executions with the same input shall not generate the same output") }
Output:
Types ¶
Click to show internal directories.
Click to hide internal directories.