gpt4 book ai didi

ios - 如何在 Swift 中验证 X509Certificate?

转载 作者:行者123 更新时间:2023-11-30 11:47:08 24 4
gpt4 key购买 nike

有谁知道如何在 swift 中验证 x509certificate?或者也许有人有它的示例链接?

我从钥匙串(keychain)中获得了证书,现在我需要验证它。

let keychainQuery: [String: Any] = [kSecClass as String: kSecClassCertificate,
kSecAttrLabel as String: "cert",
kSecReturnRef as String: kCFBooleanTrue]

var result: CFTypeRef?
let status = SecItemCopyMatching(keychainQuery as CFDictionary, &result)

guard status == errSecSuccess else { return }

entry = result as! SecCertificate

最佳答案

我找到了解决这些问题的解决方案,但仍然没有检查它。

我们需要从我们的证书创建 SecTrust 类。

让策略:SecPolicy = SecPolicyCreateBasicX509()

let trust: SecTrust?
let status = SecTrustCreateWithCertificates(entry as CFTypeRef, policy, &trust)

然后我们可以检查这个,例如日期

let trustCertStatus = SecTrustSetVerifyDate(trust!, CFDateCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent()))

关于ios - 如何在 Swift 中验证 X509Certificate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48702101/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com