You can convert your hex string back to a UInt8 array by repeating every two hexadecimal characters and initialize UInt8 from it using the UInt8 radix 16 initializer:
extension StringProtocol { var hexa: [UInt8] { var startIndex = self.startIndex return stride(from: 0, to: count, by: 2).compactMap { _ in let endIndex = index(startIndex, offsetBy: 2, limitedBy: self.endIndex) ?? self.endIndex defer { startIndex = endIndex } return UInt8(self[startIndex..<endIndex], radix: 16) } } }
Playground:
let hexaString = "e0696349774606f1b5602ffa6c2d953f" let bytes = hexaString.hexa
source share