crypt.secrets #
Secret Box
Some tools to work with encryption/decryption (symmetric)
import freeflowuniverse.crystallib.crypt.secrets
mut box:=secrets.get(secret:'mysecret')!
r:= box.encrypt('aaa')!
println(r)
assert 'aaa'==box.decrypt(r)!
hex_secret:=secrets.hex_secret()!
openssl_hex_secret:=secrets.openssl_hex_secret()!
openssl_base64_secret:=secrets.openssl_base64_secret()!
test_string2:=box.replace(txt:test_string,defaults:{"MYAPP.SOMETHING.A":secrets.DefaultSecretArgs{secret:"AAA"}})!
println(test_string2)
fn get #
fn get(args SecretBoxArgs) !SecretBox
fn hex_secret #
fn hex_secret(args StringArgs) !string
fn openssl_base64_secret #
fn openssl_base64_secret(args StringArgs) !string
fn openssl_hex_secret #
fn openssl_hex_secret(args StringArgs) !string
enum SecretType #
enum SecretType {
normal
openssl_hex
openssl_base64
}
struct SecretArgs #
@[params]
struct SecretArgs {
pub mut:
key string @[required]
default string // if it doesn't exist yet, will create it with this value
overwrite string // will overwrite the secret with this value even if it exists
cat SecretType
// reset bool
}
struct SecretBox #
struct SecretBox {
pub mut:
secret string
items map[string]string
}
fn (SecretBox) decrypt #
fn (mut b SecretBox) decrypt(txt string) !string
fn (SecretBox) encrypt #
fn (mut b SecretBox) encrypt(txt string) !string
will use our secret as configured for the hero to encrypt
struct SecretBoxArgs #
@[params]
struct SecretBoxArgs {
pub mut:
// reset bool
// interactive bool = true
secret string @[required]
}
struct StringArgs #
@[params]
struct StringArgs {
pub:
input string
}