6

Given the following HashedAuthenticationCode:

import CryptoKit
let key = SymmetricKey(size: .bits256)
let message = "Hello world!".data(using: .utf8)!
let authenticationCode = HMAC<SHA256>.authenticationCode(for: message, using: key)
print(authenticationCode) // "HMAC with SHA256: c818a1400a9995d5faafbb5d41cc88a6701b5d1a4ded8ac169498319a2597e2a"

How do I access the c818a1400a9995d5faafbb5d41cc88a6701b5d1a4ded8ac169498319a2597e2a value? Utimately this must be encoded and serialized over a URLSession, but I see no obvious property for getting the "code" part of the HAC!

Noel
  • 2,061
  • 4
  • 31
  • 47
  • 2
    The string you're describing is a hex-encoding of a sequence of bytes. See https://stackoverflow.com/questions/39075043/how-to-convert-data-to-hex-string-in-swift The only difference is that this is a MessageAuthenticationCode rather than a Data, but the approach is identical. You format each byte as a hex value. – Rob Napier Dec 18 '19 at 19:06

0 Answers0