I'm using the swift-sodium library and need a 32 bytes long public key to seal a message. However, the public key which is generated by tweetnacl-js that I got from an api is 44 bytes long. How do I convert the 44 bytes to a 32 bytes one so I can use it in the seal function?
CodePudding user response:
You have to convert your Base64-String to an UInt8-Array, which will be passed to the Swift-Sodium library for sealing. This array will be 32 bytes long.
You can convert your Base64-String using the following example:
extension Data {
public var bytes: [UInt8]{
return [UInt8](self)
}
}
// USAGE IN CODE
let data = Data(base64Encoded: <YOUR BASE64 PUBLIC KEY>, options: .ignoreUnknownCharacters)
print(data?.bytes)