Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access 'CertificateRequest' in scope #14

Open
bemisal01 opened this issue Oct 18, 2022 · 1 comment
Open

Unable to access 'CertificateRequest' in scope #14

bemisal01 opened this issue Oct 18, 2022 · 1 comment

Comments

@bemisal01
Copy link

I am trying to use this library through pods (pod 'SelfSignedCert') , after successfully getitng pod . i am importing (import SelfSignedCert) in my class. i am trying to create Self Signed Cert using this code .
do {
let (privKey, pubKey) = try SecKey.generateKeyPair(ofSize: 2048)
let certReq = CertificateRequest(forPublicKey: pubKey, subjectCommonName: "bemisalsarfraz", subjectEmailAddress: "[email protected]", keyUsage: [.DigitalSignature, .DataEncipherment])
let signedBytes = certReq.selfSign(withPrivateKey: privKey)!
let signedData = Data(signedBytes)
let signedCert = SecCertificateCreateWithData(nil, signedData as CFData)
} catch {
//handle error
print(error)
}

But i am unable to build my project because it is giving error "Cannot find 'CertificateRequest' in scope".

@svdo
Copy link
Owner

svdo commented Oct 19, 2022

Thanks for your question @bemisal01. This library is definitely not very well documented, sorry for that. I think what you're looking for is this:

guard let identity = SecIdentity.create(
    subjectCommonName: "bemisalsarfraz",
    subjectEmailAddress: "[email protected]") else {
    return
}

This will give you a self-signed SecIdentity? that is already stored in the keychain. Later on you can use things like SecIdentity.findIdentity() and SecIdentity.findAll() to retrieve previously created identities. See also https://github.com/svdo/swift-SelfSignedCert/blob/master/SelfSignedCert/SecIdentity%2BSelfSigned.swift.

I hope this helps; please don't hesitate to ask if you have more questions. Also, please have a look at https://github.com/svdo/swift-SecurityExtensions for some helpers to more easily use SecIdentity, SecCertificate, and SecKey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants