Documentation ¶
Overview ¶
The aes256 package provides simplified encryption and decryption functions using the standard crypto/aes package. It implements a 256 bit key length and the GCM cipher. The key may be a string of at least one character with an optional hash iteration value. The encrypted output may be a byte slice or a base-64 encoded string.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decrypt ¶
Decrypt accepts a key string and a ciphertext byte array. It returns a decrypted byte array.
Example ¶
package main import ( "fmt" "github.com/mkmueller/aes256" ) var ctxt []byte func main() { ptxt, err := aes256.Decrypt("carfard", ctxt) if err != nil { panic(err.Error()) } fmt.Print(string(ptxt)) }
Output: There are three great virtues of a programmer; Laziness, Impatience and Hubris
func DecryptB64 ¶
DecryptB64 accepts a key string and a base-64 encoded ciphertext string. It returns a decrypted byte array.
Example ¶
package main import ( "github.com/mkmueller/aes256" ) var err error var ptxt []byte var base64_str string func main() { ptxt, err = aes256.DecryptB64("carfard", base64_str) if err != nil { panic(err.Error()) } }
Output:
func Encrypt ¶
Encrypt accepts a key string and a plaintext byte array. It returns an encrypted byte array.
Example ¶
package main import ( "github.com/mkmueller/aes256" ) var err error var txt []byte = []byte("There are three great virtues of a programmer; Laziness, Impatience and Hubris") var ctxt []byte func main() { ctxt, err = aes256.Encrypt("carfard", txt) if err != nil { panic(err.Error()) } }
Output:
func EncryptB64 ¶
Encrypt accepts a key string and a plaintext byte array. It returns an encrypted base-64 encoded string.
Example ¶
package main import ( "github.com/mkmueller/aes256" ) var err error var txt []byte = []byte("There are three great virtues of a programmer; Laziness, Impatience and Hubris") var base64_str string func main() { base64_str, err = aes256.EncryptB64("carfard", txt) if err != nil { panic(err.Error()) } }
Output:
Types ¶
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
func New ¶
New accepts a key string and an optional rehash value. The supplied key will be rehashed the number of times indicated by the optional rehash value. A new Cipher instance will be returned.
Example ¶
package main import ( "github.com/mkmueller/aes256" ) var err error var aes *aes256.Cipher func main() { aes, err = aes256.New("carfard") if err != nil { panic(err.Error()) } }
Output:
func (*Cipher) Decrypt ¶
Decrypt accepts a ciphertext byte array and returns a plaintext byte array.
Example ¶
package main import ( "github.com/mkmueller/aes256" ) var ctxt []byte var ptxt []byte func main() { aes, err := aes256.New("carfard") if err != nil { panic(err.Error()) } ptxt, err = aes.Decrypt(ctxt) }
Output:
func (*Cipher) DecryptB64 ¶
DecryptB64 accepts a base-64 encoded ciphertext string and returns a decrypted byte array.
Example ¶
package main import ( "github.com/mkmueller/aes256" ) var ptxt []byte var base64_str string func main() { aes, err := aes256.New("carfard") if err != nil { panic(err.Error()) } ptxt, err = aes.DecryptB64(base64_str) }
Output:
func (*Cipher) Encrypt ¶
Encrypt accepts a plaintext byte array and returns an encrypted byte array.
Example ¶
package main import ( "github.com/mkmueller/aes256" ) var err error var txt []byte = []byte("There are three great virtues of a programmer; Laziness, Impatience and Hubris") var aes *aes256.Cipher var ctxt []byte func main() { txt = []byte("There are three great virtues of a programmer; Laziness, Impatience and Hubris") aes, err = aes256.New("carfard") if err != nil { panic(err.Error()) } ctxt, err = aes.Encrypt(txt) }
Output:
func (*Cipher) EncryptB64 ¶
EncryptB64 accepts a plaintext byte array and returns an encrypted base-64 encoded ciphertext string.
Example ¶
package main import ( "github.com/mkmueller/aes256" ) var err error var txt []byte = []byte("There are three great virtues of a programmer; Laziness, Impatience and Hubris") var aes *aes256.Cipher var base64_str string func main() { aes, err = aes256.New("carfard") if err != nil { panic(err.Error()) } base64_str, err = aes.EncryptB64(txt) }
Output: