getting error while verifying private key signature using cryptokit
What i tried:
func signMessage(_ message: String, withPrivateKey privateKey: Data) -> Data {
do{
let key = try P256.Signing.PrivateKey(rawRepresentation: privateKey) // here it throws error
let signature = try key.signature(for: message.data(using: .utf8)!)
return signature.rawRepresentation
}catch{
print(error)
return Data()
}
}
Error: underlyingCoreCryptoError(error: -1)
Additional Info: message is kind of header token and looks like this
eyJhbGciddJFUzI1diIsImtpZdI6IjdXNFQ5dlFRdEMifQ==.eyJpYXQiOjE2Off5MTEwOfksImlzcyI6fjdWUTfQOExRfFMifQ==
should i need to trim message
with =
?
i am not sure what's wrong with this code but it throws underlyingCoreCryptoError
.
Suggestion will be thankful.