feat: add secure_enclave.swift
This commit is contained in:
23
secure_enclave.swift
Normal file
23
secure_enclave.swift
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// https://www.andyibanez.com/posts/cryptokit-secure-enclave/
|
||||||
|
// import Swift import Foundation
|
||||||
|
// import Security
|
||||||
|
import CryptoKit
|
||||||
|
|
||||||
|
let se = SecureEnclave.isAvailable;
|
||||||
|
print("Supports SE: \(se)");
|
||||||
|
|
||||||
|
var error: Unmanaged<CFError>? = nil;
|
||||||
|
guard let accessCtrl = SecAccessControlCreateWithFlags(
|
||||||
|
nil,
|
||||||
|
kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
|
||||||
|
[.privateKeyUsage, .biometryCurrentSet],
|
||||||
|
&error
|
||||||
|
) else {
|
||||||
|
throw error!.takeRetainedValue() as Swift.Error;
|
||||||
|
} var privateKeyReference = try CryptoKit.SecureEnclave.P256.KeyAgreement.PrivateKey.init(
|
||||||
|
accessControl: accessCtrl
|
||||||
|
);
|
||||||
|
|
||||||
|
print("Private key reference: \(privateKeyReference)");
|
||||||
|
print("Private key reference - publicKey: \(privateKeyReference.publicKey)");
|
||||||
|
print("Private key reference - dataRepresentation: \(privateKeyReference.dataRepresentation)");
|
||||||
Reference in New Issue
Block a user