我是Crystal的新手,在运行以下代码时遇到错误no overload matches 'Slice(UInt8)#+' with type Slice(UInt8)
,
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
感谢您的帮助。在线版本为here
答案 0 :(得分:1)
在编译失败的行中,您将“两个切片”“加在一起”。
根据此规范:
https://github.com/crystal-lang/crystal/blob/master/spec/std/openssl/cipher_spec.cr
您基本上必须先将其添加到IO,然后才能将其转换为字符串。
例如:https://gist.github.com/rdp/349161fd5b10208dc7445fb5d9beefae(尽管它似乎只能在本地播放,而不能用于水晶游戏)