@rogerdpack nothing I’ve tried has compiled, just completely unsure of the optimal way to do this.
Basically I figured that a Slice(UInt16) is a pointer to some memory and it should be possible to represent that memory as Bytes given you can call #bytesize to get the size
You’re on the correct path. As the error message says, you need to pass a pointer as first argument of Slice.new. You can use password.to_unsafe to get a pointer to the slice. However, pointer must be of the result type you want to get, so you need a pointer cast from Pointer(UInt16) to Pointer(UInt8):
cipher = OpenSSL::Cipher.new("aes-256-cbc")
cipher.padding = true
cipher.decrypt
# LE for little endian and avoids a byte order mark
password = @password.encode("UTF-16LE")
key = IO::Memory.new(Bytes.new(32))
key.write password
cipher.key = key.to_slice
As using the underlying bytes directly ignores endianness and we are targeting AMD64 and ARM64 platforms.