Skip to content

Instantly share code, notes, and snippets.

@tsif
Created October 8, 2019 12:17
Show Gist options
  • Save tsif/10338d69fc85975783dc0259c50741ae to your computer and use it in GitHub Desktop.
Save tsif/10338d69fc85975783dc0259c50741ae to your computer and use it in GitHub Desktop.
let path = Bundle.main.path(forResource: "video", ofType: "mp4")!
let data = FileManager.default.contents(atPath: path)!
let key = SymmetricKey(size: .bits256) // key shared by both parties
let authentication = HMAC<SHA256>.authenticationCode(for: data,
using: key)
let authenticationData = Data(authentication)
// ~~~~~~ travel accross the network ~~~~~~~
if (HMAC<SHA256>.isValidAuthenticationCode(authenticationData,
authenticating: data,
using: key)) {
print("Validated ✅")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment