当 运行 代码时,没有重载与类型 Slice(UInt8) 匹配 'Slice(UInt8)#+'
No overload matches 'Slice(UInt8)#+' with type Slice(UInt8) when running code
我是 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
在编译失败的行中,您 "adding" 两个切片在一起。
根据这个规范:
https://github.com/crystal-lang/crystal/blob/master/spec/std/openssl/cipher_spec.cr
您基本上必须先将其添加到 IO,然后才能将其转换为字符串。
例如:https://gist.github.com/rdp/349161fd5b10208dc7445fb5d9beefae(虽然它似乎只能在本地工作而不是 crystal 播放)
我是 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
在编译失败的行中,您 "adding" 两个切片在一起。
根据这个规范:
https://github.com/crystal-lang/crystal/blob/master/spec/std/openssl/cipher_spec.cr
您基本上必须先将其添加到 IO,然后才能将其转换为字符串。
例如:https://gist.github.com/rdp/349161fd5b10208dc7445fb5d9beefae(虽然它似乎只能在本地工作而不是 crystal 播放)