Skip to content

Instantly share code, notes, and snippets.

@cardoso
Last active November 2, 2020 15:36
Show Gist options
  • Save cardoso/c9e381b78671263cfc2e65d568f77bdc to your computer and use it in GitHub Desktop.
Save cardoso/c9e381b78671263cfc2e65d568f77bdc to your computer and use it in GitHub Desktop.
import Foundation
import CryptoKit
func deriveSymmetricKey(privateKey: P256.KeyAgreement.PrivateKey, publicKey: P256.KeyAgreement.PublicKey) throws -> SymmetricKey {
let sharedSecret = try privateKey.sharedSecretFromKeyAgreement(with: publicKey)
let symmetricKey = sharedSecret.hkdfDerivedSymmetricKey(
using: SHA256.self,
salt: "My Key Agreement Salt".data(using: .utf8)!,
sharedInfo: Data(),
outputByteCount: 32
)
return symmetricKey
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment