Documentation
¶
Index ¶
- func CBCDecrypt(ciphertext, key []byte) ([]byte, error)
- func CBCEncrypt(key, plaintext []byte, iv []byte) ([]byte, error)
- func CBCEncryptRandom(key, plaintext []byte) ([]byte, error)
- func CFBDecrypt(ciphertext, key []byte) ([]byte, error)
- func CFBEncrypt(key, plaintext []byte, iv []byte) ([]byte, error)
- func CFBEncryptRandom(key, plaintext []byte) ([]byte, error)
- func CTRDecrypt(ciphertext, key []byte) ([]byte, error)
- func CTREncrypt(key, plaintext []byte, iv []byte) ([]byte, error)
- func CTREncryptRandom(key, plaintext []byte) ([]byte, error)
- func GCMDecrypt(ciphertext, key []byte) ([]byte, error)
- func GCMEncrypt(key, plaintext []byte, nonce []byte) ([]byte, error)
- func GCMEncryptRandom(key, plaintext []byte) ([]byte, error)
- func OFBDecrypt(ciphertext, key []byte) ([]byte, error)
- func OFBEncrypt(key, plaintext, iv []byte) ([]byte, error)
- func OFBEncryptRandom(key, plaintext []byte) ([]byte, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CBCDecrypt ¶
func CBCEncrypt ¶
Example ¶
package main
import (
"encoding/hex"
"fmt"
aes_ "github.com/searKing/golang/go/crypto/aes"
)
func main() {
// Load your secret key from a safe place and reuse it across multiple
// NewCipher calls. (Obviously don't use this example key for anything
// real.) If you want to convert a passphrase to a key, use a suitable
// package like bcrypt or scrypt.
key, _ := hex.DecodeString("6368616e676520746869732070617373")
plaintext := []byte("exampleplaintext")
ciphertext, err := aes_.CBCEncrypt(key, plaintext, nil)
if err != nil {
panic(err)
}
// It's important to remember that ciphertexts must be authenticated
// (i.e. by using crypto/hmac) as well as being encrypted in order to
// be secure.
fmt.Println("encrypted:")
fmt.Printf("%x\n", ciphertext)
plaintext, err = aes_.CBCDecrypt(ciphertext, key)
if err != nil {
panic(err)
}
fmt.Println("decrypted:")
fmt.Printf("%s\n", string(plaintext))
}
Output: encrypted: 00000000000000000000000000000000f42512e1e4039213bd449ba47faa1b7408eac45dbf536e5016511f86035707c6 decrypted: exampleplaintext
func CBCEncryptRandom ¶
func CFBDecrypt ¶
func CFBEncryptRandom ¶
func CTRDecrypt ¶
func CTREncrypt ¶
Example ¶
package main
import (
"encoding/hex"
"fmt"
aes_ "github.com/searKing/golang/go/crypto/aes"
)
func main() {
// Load your secret key from a safe place and reuse it across multiple
// NewCipher calls. (Obviously don't use this example key for anything
// real.) If you want to convert a passphrase to a key, use a suitable
// package like bcrypt or scrypt.
key, _ := hex.DecodeString("6368616e676520746869732070617373")
plaintext := []byte("exampleplaintext")
ciphertext, err := aes_.CTREncrypt(key, plaintext, nil)
if err != nil {
panic(err)
}
// It's important to remember that ciphertexts must be authenticated
// (i.e. by using crypto/hmac) as well as being encrypted in order to
// be secure.
fmt.Println("encrypted:")
fmt.Printf("%x\n", ciphertext)
plaintext, err = aes_.CTRDecrypt(ciphertext, key)
if err != nil {
panic(err)
}
fmt.Println("decrypted:")
fmt.Printf("%s\n", string(plaintext))
}
Output: encrypted: 00000000000000000000000000000000d91399c43f6adaef3d909876e79904a93b1144928bc98a4e78f38c23b706610a decrypted: exampleplaintext
func CTREncryptRandom ¶
func GCMDecrypt ¶
func GCMEncrypt ¶
Example ¶
package main
import (
"encoding/hex"
"fmt"
aes_ "github.com/searKing/golang/go/crypto/aes"
)
func main() {
// Load your secret key from a safe place and reuse it across multiple
// NewCipher calls. (Obviously don't use this example key for anything
// real.) If you want to convert a passphrase to a key, use a suitable
// package like bcrypt or scrypt.
key, _ := hex.DecodeString("6368616e676520746869732070617373")
plaintext := []byte("exampleplaintext")
ciphertext, err := aes_.GCMEncrypt(key, plaintext, nil)
if err != nil {
panic(err)
}
// It's important to remember that ciphertexts must be authenticated
// (i.e. by using crypto/hmac) as well as being encrypted in order to
// be secure.
fmt.Println("encrypted:")
fmt.Printf("%x\n", ciphertext)
plaintext, err = aes_.GCMDecrypt(ciphertext, key)
if err != nil {
panic(err)
}
fmt.Println("decrypted:")
fmt.Printf("%s\n", string(plaintext))
}
Output: encrypted: 0000000000000000000000000b2591cb60a33bdfeb61a0d35207a4196f1e5d1f6fe2b32198e09765ee28bd17d08567996caca50cd7049c07d1db15b5 decrypted: exampleplaintext
func GCMEncryptRandom ¶
func OFBDecrypt ¶
func OFBEncrypt ¶
Example ¶
package main
import (
"encoding/hex"
"fmt"
aes_ "github.com/searKing/golang/go/crypto/aes"
)
func main() {
// Load your secret key from a safe place and reuse it across multiple
// NewCipher calls. (Obviously don't use this example key for anything
// real.) If you want to convert a passphrase to a key, use a suitable
// package like bcrypt or scrypt.
key, _ := hex.DecodeString("6368616e676520746869732070617373")
plaintext := []byte("exampleplaintext")
ciphertext, err := aes_.OFBEncrypt(key, plaintext, nil)
if err != nil {
panic(err)
}
// It's important to remember that ciphertexts must be authenticated
// (i.e. by using crypto/hmac) as well as being encrypted in order to
// be secure.
fmt.Println("encrypted:")
fmt.Printf("%x\n", ciphertext)
plaintext, err = aes_.OFBDecrypt(ciphertext, key)
if err != nil {
panic(err)
}
fmt.Println("decrypted:")
fmt.Printf("%s\n", string(plaintext))
}
Output: encrypted: 00000000000000000000000000000000d91399c43f6adaef3d909876e79904a9729f985422616b9f45b757ac9e7a879e decrypted: exampleplaintext
func OFBEncryptRandom ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.