Reputation: 105
I'm new to Crystal and came across the error no overload matches 'Slice(UInt8)#+' with type Slice(UInt8)
when running the following code,
require "openssl"
NAME = "Boy"
cipher = OpenSSL::Cipher.new("AES-256-CBC")
cipher.encrypt
key = cipher.random_key
iv = cipher.random_iv
# Username
encrypted_name = cipher.update(NAME) + cipher.final
puts encrypted_name
decipher = OpenSSL::Cipher.new("AES-256-CBC")
decipher.decrypt
decipher.key = key
decipher.iv = iv
# Username
plain_name = decipher.update(encrypted_name) + decipher.final
puts plain_name
Any help is appreciated. The online ver is here
Upvotes: 1
Views: 104
Reputation: 66851
In the line that fails compilation you're "adding" two slices together.
According to this spec:
https://github.com/crystal-lang/crystal/blob/master/spec/std/openssl/cipher_spec.cr
You basically have to add that to an IO first then you can convert it to a string.
ex: https://gist.github.com/rdp/349161fd5b10208dc7445fb5d9beefae (though it seems to only work locally not on crystal play)
Upvotes: 1