Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AES128 ¶
type AES128 struct {
// contains filtered or unexported fields
}
AES128 provides AES encryption with a 128-bit key.
Example ¶
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/ciphering" ) func main() { // Create a new AES-128 handler with a secret key aes128, err := ciphering.NewAES128("mysecret") if err != nil { fmt.Println(err) } // Data to be encrypted plaintext := []byte("This is a secret message") // Encrypt the data ciphertext, err := aes128.Encrypt(plaintext) if err != nil { fmt.Println(err) } // Decrypt the data decrypted, err := aes128.Decrypt(ciphertext) if err != nil { fmt.Println(err) } fmt.Printf("Decrypted: %s\n", decrypted) }
Output: Decrypted: This is a secret message
func NewAES128 ¶
NewAES128 creates a new AES-128 handler using the provided secret. The secret is hashed with SHA-256 to derive a 128-bit key and AAD.
type AES256 ¶
type AES256 struct {
// contains filtered or unexported fields
}
AES256 provides AES encryption with a 256-bit key.
Example ¶
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/ciphering" ) func main() { // Create a new AES-256 handler with a secret key aes256, err := ciphering.NewAES256("anothersecret") if err != nil { fmt.Println(err) } // Data to be encrypted plaintext := []byte("Another secret message") // Encrypt the data ciphertext, err := aes256.Encrypt(plaintext) if err != nil { fmt.Println(err) } // Decrypt the data decrypted, err := aes256.Decrypt(ciphertext) if err != nil { fmt.Println(err) } fmt.Printf("Decrypted: %s\n", decrypted) }
Output: Decrypted: Another secret message
func NewAES256 ¶
NewAES256 creates a new AES-256 handler using the provided secret. The secret is hashed with SHA-512 to derive a 256-bit key and AAD.
Click to show internal directories.
Click to hide internal directories.