Documentation ¶
Index ¶
- Constants
- func CombineKeys(privateKey, publicKey, aesSeed string) string
- func DecryptBytesAes(data []byte, aesKey string) ([]byte, error)
- func DecryptBytesAge(data []byte, privateKey string) ([]byte, error)
- func GenerateKeys() (string, string, string, error)
- func GenerateValue(template string) (string, error)
- func RandomString(n int) (string, error)
- type Algorithm
Constants ¶
const Aes = Algorithm("aes")
const Age = Algorithm("age")
Variables ¶
This section is empty.
Functions ¶
func CombineKeys ¶ added in v0.21.1
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 DecryptBytesAge ¶ added in v0.22.0
func GenerateKeys ¶ added in v0.21.1
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
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 ¶
RandomString generates a cryptographically-unique secure random string.