Ok I have tried dozens of cryptography attempts to replicate the answer in:
String: 1538831506GET/v2/user
key: R11ScShruvOGBkwMhxCPJEmWLKnwpeLf
Expected Result: b4f28c23d9195a3903eeb8aa6214f632f415bbdfbfa2c58f08dad96529bfbdc2
However nothing seems to get the same answer. I have tried CryptoSwift, CommonCrypto (objective-c), IDZSwiftCommonCrypto.. and nothing seems to work.
Here is some sample code:
func getHMacSHA256(forMessage message: String, key: String) -> String? {
//CommonCrypto
let str = message
let hmac_sha256 = str.hmac(algorithm: .sha256, key: key)
print(hmac_sha256)
let hex: String = hmac_sha256.unicodeScalars.filter { $0.isASCII }
.map { String(format: "%X", $0.value) }
.joined()
print(hex)
//IDZSwiftCommonCrypto
let hMacVal = HMAC(algorithm: HMAC.Algorithm.sha256, key: key).update(string: message)?.final()
if let encryptedData = hMacVal {
let decData = NSData(bytes: encryptedData, length: Int(encryptedData.count))
let base64String = decData.base64EncodedString(options: .lineLength64Characters)
let hexString = (decData as Data).hexEncodedString()
print("base64String: \(base64String)")
print("hexString: \(hexString)")
return hexString
} else {
return nil
}
}