-
Notifications
You must be signed in to change notification settings - Fork 6
/
SwiftClass.swift
42 lines (32 loc) · 1.53 KB
/
SwiftClass.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Foundation
import CryptoKit
@objc class SwiftClass: NSObject {
@objc override init() {
super.init()
}
// Function demonstrating usage of a Swift-only API.
@objc func runKeyCheck() -> Bool {
let protocolSalt = "Shelley Swift Node.js Addon".data(using: .utf8)!
let onePrivateKey = P256.KeyAgreement.PrivateKey()
let onePublicKey = onePrivateKey.publicKey
let twoPrivateKey = P256.KeyAgreement.PrivateKey()
let twoPublicKey = twoPrivateKey.publicKey
let oneSharedSecret = try! onePrivateKey.sharedSecretFromKeyAgreement(with: twoPublicKey)
let oneSymmetricKey = oneSharedSecret.hkdfDerivedSymmetricKey(using: SHA256.self,
salt: protocolSalt,
sharedInfo: Data(),
outputByteCount: 32)
let twoSharedSecret = try! twoPrivateKey.sharedSecretFromKeyAgreement(with: onePublicKey)
let twoSymmetricKey = twoSharedSecret.hkdfDerivedSymmetricKey(using: SHA256.self,
salt: protocolSalt,
sharedInfo: Data(),
outputByteCount: 32)
return twoSymmetricKey == oneSymmetricKey
}
@objc func sayHello() -> Void {
print("hello")
}
@objc func addX(x: Int, andY y: Int) -> Int {
return x + y
}
}