Skip to content

Instantly share code, notes, and snippets.

@tsif
Last active October 8, 2019 14:51
Show Gist options
  • Save tsif/3c95187501639553bdefa3b53bf0fe3e to your computer and use it in GitHub Desktop.
Save tsif/3c95187501639553bdefa3b53bf0fe3e to your computer and use it in GitHub Desktop.
let key = SymmetricKey(size: .bits256)
let path = Bundle.main.path(forResource: "video", ofType: "mp4")!
let data = FileManager.default.contents(atPath: path)!
// To encrypt
let encryptedData = try! ChaChaPoly.seal(data, using: key)
// To decrypt
let sealedBox = try! ChaChaPoly.SealedBox(combined: encryptedData)
let decryptedData = try! ChaChaPoly.open(sealedBox, using: key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment