Skip to content

Instantly share code, notes, and snippets.

@tsif
Last active October 8, 2019 14:51
Show Gist options
  • Save tsif/e6ec92c0f115cb0d23c1ce6ef022ce24 to your computer and use it in GitHub Desktop.
Save tsif/e6ec92c0f115cb0d23c1ce6ef022ce24 to your computer and use it in GitHub Desktop.
let privateKey = Curve25519.Signing.PrivateKey()
let publicKey = privateKey.publicKey // publicize freely
let publicKeyData = publicKey.rawRepresentation
let signingPublicKey = try! Curve25519.Signing.PublicKey(rawRepresentation: publicKeyData)
// sign some data with your private key
let data = "All your base are belong to us".data(using: .utf8)!
let signature = try! privateKey.signature(for: data)
if signingPublicKey.isValidSignature(signature, for: data) {
print("The signature is valid.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment