crypto

package
v0.25.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2024 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const Aes = Algorithm("aes")
View Source
const Age = Algorithm("age")

Variables

This section is empty.

Functions

func CombineKeys added in v0.21.1

func CombineKeys(privateKey, publicKey, aesSeed string) string

CombineKeys takes a private key, a public key, and an AES seed, and combines them into a single string, separating each with a newline.

Parameters: - privateKey: The X25519 private key as a string. - publicKey: The X25519 public key as a string. - aesSeed: The AES seed for symmetric encryption as a string.

Returns:

  • A single string containing the private key, public key, and AES seed, each separated by a newline.

func DecryptBytesAes added in v0.22.0

func DecryptBytesAes(data []byte, aesKey string) ([]byte, error)

func DecryptBytesAge added in v0.22.0

func DecryptBytesAge(data []byte, privateKey string) ([]byte, error)

func GenerateKeys added in v0.21.1

func GenerateKeys() (string, string, string, error)

GenerateKeys generates a pair of X25519 keys for public key encryption using the age library, as well as an AES seed for symmetric encryption.

Returns: - publicKey: The X25519 public key as a string. - privateKey: The X25519 private key as a string. - aesSeed: A generated AES seed for symmetric encryption. - error: An error object if any step in the process fails.

func GenerateValue added in v0.22.0

func GenerateValue(template string) (string, error)

GenerateValue creates a string based on a template with embedded generator expressions. The generator expressions specify character ranges and lengths for random string parts.

Parameters: template - The string template containing generator expressions.

Returns: The generated string adhering to the template specifications. An error if any generator expression is invalid or if the string generation fails.

Example Usage:

result, _ := Generate(`foo[\w]{8}bar`)
log.Printf("result0=%v", result)
result, _ = Generate(`admin[a-z0-9]{3}`)
log.Printf("result1=%v", result)
result, _ = Generate(`admin[a-z0-9]{3}something[\w]{3}`)
log.Printf("result1=%v", result)
result, _ = Generate(`pass[a-zA-Z0-9]{12}`)
log.Printf("result2=%v", result)
result, _ = Generate(`pass[a-Z]{8}`)
log.Printf("result3=%v", result)
result, err := Generate(`pass[z-a]{8}`)
log.Printf("result4=%v; err=%v", result, err)
result, _ = Generate(`foo[\d]{8}bar`)
log.Printf("result5=%v", result)

Example Output:

2024/01/04 06:37:30 result0=foo{A?1o!u9bar
2024/01/04 06:37:30 result1=admin7sg
2024/01/04 06:37:30 result1=adminsw8something^5^
2024/01/04 06:37:30 result2=passqWv04txU5sKs
2024/01/04 06:37:30 result3=passlRxDTdMz
2024/01/04 06:37:30 result4=; err=invalid range specified: z-a
2024/01/04 06:37:30 result5=foo73579557bar

func RandomString

func RandomString(n int) (string, error)

RandomString generates a cryptographically-unique secure random string.

Types

type Algorithm added in v0.22.0

type Algorithm string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL