feat: udpate swift lib
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import SwiftRs
|
import SwiftRs
|
||||||
import AppKit
|
|
||||||
import CryptoKit
|
import CryptoKit
|
||||||
import LocalAuthentication
|
import LocalAuthentication
|
||||||
|
|
||||||
@@ -23,7 +22,7 @@ func generateSecureEnclaveP256KeyPair() -> SRString {
|
|||||||
return SRString("err:\(error.debugDescription)")
|
return SRString("err:\(error.debugDescription)")
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
let privateKeyReference = try CryptoKit.SecureEnclave.P256.KeyAgreement.PrivateKey.init(
|
let privateKeyReference = try SecureEnclave.P256.KeyAgreement.PrivateKey.init(
|
||||||
accessControl: accessCtrl
|
accessControl: accessCtrl
|
||||||
);
|
);
|
||||||
let publicKeyBase64 = privateKeyReference.publicKey.x963Representation.base64EncodedString()
|
let publicKeyBase64 = privateKeyReference.publicKey.x963Representation.base64EncodedString()
|
||||||
@@ -36,7 +35,7 @@ func generateSecureEnclaveP256KeyPair() -> SRString {
|
|||||||
|
|
||||||
@_cdecl("compute_secure_enclave_p256_ecdh")
|
@_cdecl("compute_secure_enclave_p256_ecdh")
|
||||||
func computeSecureEnclaveP256Ecdh(privateKeyDataRepresentation: SRString, ephemeraPublicKey: SRString) -> SRString {
|
func computeSecureEnclaveP256Ecdh(privateKeyDataRepresentation: SRString, ephemeraPublicKey: SRString) -> SRString {
|
||||||
guard let dataRepresentation = Data(
|
guard let privateKeyDataRepresentation = Data(
|
||||||
base64Encoded: privateKeyDataRepresentation.toString()
|
base64Encoded: privateKeyDataRepresentation.toString()
|
||||||
) else {
|
) else {
|
||||||
return SRString("err:private key base64 decode failed")
|
return SRString("err:private key base64 decode failed")
|
||||||
@@ -49,11 +48,11 @@ func computeSecureEnclaveP256Ecdh(privateKeyDataRepresentation: SRString, epheme
|
|||||||
do {
|
do {
|
||||||
let context = LAContext();
|
let context = LAContext();
|
||||||
let p = try SecureEnclave.P256.KeyAgreement.PrivateKey(
|
let p = try SecureEnclave.P256.KeyAgreement.PrivateKey(
|
||||||
dataRepresentation: dataRepresentation,
|
dataRepresentation: privateKeyDataRepresentation,
|
||||||
authenticationContext: context
|
authenticationContext: context
|
||||||
)
|
)
|
||||||
|
|
||||||
let ephemeralPublicKey = try CryptoKit.P256.KeyAgreement.PublicKey.init(derRepresentation: ephemeralPublicKeyRepresentation)
|
let ephemeralPublicKey = try P256.KeyAgreement.PublicKey.init(derRepresentation: ephemeralPublicKeyRepresentation)
|
||||||
|
|
||||||
let sharedSecret = try p.sharedSecretFromKeyAgreement(
|
let sharedSecret = try p.sharedSecretFromKeyAgreement(
|
||||||
with: ephemeralPublicKey)
|
with: ephemeralPublicKey)
|
||||||
|
|||||||
Reference in New Issue
Block a user