I need help for the following scenario. I need to convert bytes to string in Swift language. Here is my code.
let ciphertext = try aes.encrypt(Array("Password123".utf8))
print("ciphertext: \(ciphertext)")
// output ciphertext: [148, 177, 49, 193, 100, 184, 232, 51, 26, 170, 146, 114, 77, 244, 29, 172]
let nsdata = NSData(bytes: ciphertext as [UInt8], length: ciphertext.count)
print("nsdata: \(nsdata)")
// output nsdata: <94b131c1 64b8e833 1aaa9272 4df41dac>
let str = String(data: nsdata as Data, encoding: String.Encoding.utf8)
print("cipherStr: \(str)")
// output cipherStr: nil
I always got "NIL" value when I try to convert bytes to String.