CI iOS macOS

locksmith

这是一个用 Swift 编写的 macOS/iOS 钥匙串访问包装器。locksmith 提供了一种简单且安全的方式,使用 iOS 钥匙串来存储和检索敏感数据。

功能

安装

Swift 包管理器

您可以使用 Swift 包管理器 安装 Wheel,方法是将以下行添加到您的 Package.swift 文件中

dependencies: [
    .package(url: "https://github.com/swiftDevelopmentPackages/locksmith.git", from: "1.0.0")
]

然后,将 wheel 添加到您的目标依赖项中

targets: [
    .target(name: "YourTarget", dependencies: ["locksmith"]),
]

或者,只需使用 XCode 的包依赖项选项卡添加。

用法

初始化

locksmith 支持 accessGroup 标识符,用于在不同的应用程序和扩展程序之间进行可选的钥匙串共享。

let locksmith = Locksmith(service: "com.example.keychain", accessGroup: "your.access.group")

保存

let dataToSave = "Secret Data"
locksmith.save(key: "secretKey", value: dataToSave)

读取

if let retrievedData: String = locksmith.read(key: "secretKey") {
    print("Retrieved Data: \(retrievedData)")
}

删除

locksmith.delete(key: "secretKey")