Skip to content

Instantly share code, notes, and snippets.

@mlaster
Created October 17, 2018 14:26
Show Gist options
  • Save mlaster/c3d00afd71839abfb4de62874c4d017d to your computer and use it in GitHub Desktop.
Save mlaster/c3d00afd71839abfb4de62874c4d017d to your computer and use it in GitHub Desktop.
extension Data {
func encrypt(key: Data) {
let ivData = Data.randomBytes(count: kCCKeySizeAES128)
var tag = Data(count: kCCKeySizeAES128)
var cipherText = Data(count: count)
_ = cipherText.withUnsafeMutableBytes { (cipherPtr) in
_ = tag.withUnsafeMutableBytes { (tagPtr) in
_ = ivData.withUnsafeBytes { (ivPtr) in
_ = key.withUnsafeBytes { (keyPtr) in
_ = keyPtr
_ = ivPtr
_ = tagPtr
_ = cipherPtr
// Do crypto stuff here
}
}
}
}
}
}
@mlaster
Copy link
Author

mlaster commented Oct 17, 2018

I get a compile error on line 12: 'inout Data' is not convertible to 'Data'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment