# example value make by `php artisan key:generate`
# ENV["APL_KEY"] = "base64:dTOymAUpqvF/2tOxnQdakYHuL66HlmkElovGwumCiPE="
struct SimpleEncrypt
def initialize(
@key : String = ENV["APP_KEY"],
@cypher = AES128)
end
def encrypt (data : String) : String
# encrypts the string
end
def decrypt (data : String) : String
# decrypts the string
end
end
e = SimpleEncrypt.new()
value = "any string"
encrypted_value = e.encrypt(value)
value2 = e.decrypt(encrypted_value)
puts value2 == value
# true
I couldn’t find anything in the standard library or http://crystalshards.xyz/ for this, but I did find things suited for adjacent topics like password hashing, SSL, certificates, MD5/SHA.
I think this would make a great STD or shard, but I don’t know the primitives for doing this myself.
A shard is not necessary for Bcrypt, it is easy enough with the stdlib.
For OpenSSL, I can agree not so much. I hope the API will be revisited and more type safe after the 1.0.