2

I am trying to obtain the results of a hmac sha256 as a String ,something similar to this "asdafsdfafs13rfafAafaasdfadfasdfa", but the code snippet below generates this byteArray. enter image description here

var combinedString = "key1=val1&key2=val2"
        
       //Using import BlueCryptor
        let key = CryptoUtils.byteArray(fromHex: apikey!)
        let data : [UInt8] = CryptoUtils.byteArray(fromHex: combinedString)
        let hmac = HMAC(using: HMAC.Algorithm.sha256, key: key).update(byteArray: data)?.final()
        
        
        print(hmac)

How do i convert it from a byteArray to a string ?

Ron Brian
  • 41
  • 4
  • 1
    @Alladinian, the duped answer won't work for this question. That question is about converting UTF-8 encoded bytes into String. The output of an HMAC is random bytes; it's not UTF-8. This question needs Base64. – Rob Napier Oct 29 '20 at 13:31
  • 1
    @RobNapier Thanks for pointing out. I guess I got confused by the wording. Voted to reopen. Thanks! – Alladinian Oct 29 '20 at 13:33

0 Answers0