{"id":22820561,"url":"https://github.com/cbaker6/certificatesigningrequest","last_synced_at":"2025-09-07T00:38:33.430Z","repository":{"id":42443125,"uuid":"71505029","full_name":"cbaker6/CertificateSigningRequest","owner":"cbaker6","description":"Generate a certificate signing request (CSR) programmatically on iOS/macOS/watchOS/tvOS devices","archived":false,"fork":false,"pushed_at":"2024-11-18T18:01:57.000Z","size":1466,"stargazers_count":108,"open_issues_count":2,"forks_count":36,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-08-20T23:28:08.014Z","etag":null,"topics":["certificate-signing-request","cocoapods","csr","elliptic-curve-diffie-hellman","elliptic-curves","hacktoberfest","ios","keychain","pki","privatekey","publickey","rsa","secure-enclave","swift","swift-package-manager"],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/cbaker6/CertificateSigningRequest/main/documentation/certificatesigningrequest","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cbaker6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-20T21:15:47.000Z","updated_at":"2025-08-20T07:45:36.000Z","dependencies_parsed_at":"2024-12-12T15:33:01.736Z","dependency_job_id":"def7d833-13d1-40a2-a8d2-c8c715995468","html_url":"https://github.com/cbaker6/CertificateSigningRequest","commit_stats":{"total_commits":45,"total_committers":6,"mean_commits":7.5,"dds":0.1333333333333333,"last_synced_commit":"01c5ccff63339dfbad6b5ddcdc671f4b1b6becb3"},"previous_names":["cbaker6/certificatesigningrequestswift","cbaker6/ioscsrswift"],"tags_count":38,"template":false,"template_full_name":null,"purl":"pkg:github/cbaker6/CertificateSigningRequest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbaker6%2FCertificateSigningRequest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbaker6%2FCertificateSigningRequest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbaker6%2FCertificateSigningRequest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbaker6%2FCertificateSigningRequest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cbaker6","download_url":"https://codeload.github.com/cbaker6/CertificateSigningRequest/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbaker6%2FCertificateSigningRequest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273983073,"owners_count":25202092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["certificate-signing-request","cocoapods","csr","elliptic-curve-diffie-hellman","elliptic-curves","hacktoberfest","ios","keychain","pki","privatekey","publickey","rsa","secure-enclave","swift","swift-package-manager"],"created_at":"2024-12-12T15:26:35.815Z","updated_at":"2025-09-07T00:38:33.381Z","avatar_url":"https://github.com/cbaker6.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CertificateSigningRequest\n[![Documentation](https://img.shields.io/badge/read_-docs-2196f3.svg)](https://swiftpackageindex.com/cbaker6/CertificateSigningRequest/documentation)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fcbaker6%2FCertificateSigningRequest%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/cbaker6/CertificateSigningRequest)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fcbaker6%2FCertificateSigningRequest%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/cbaker6/CertificateSigningRequest)\n[![CI Status](https://github.com/cbaker6/CertificateSigningRequest/workflows/build/badge.svg?branch=main)](https://github.com/cbaker6/CertificateSigningRequest/actions?query=workflow%3Abuild+branch%3Amain)\n[![Codecov](https://codecov.io/gh/cbaker6/CertificateSigningRequest/branches/main/graph/badge.svg)](https://codecov.io/gh/cbaker6/CertificateSigningRequest/branches/main)\n[![Pod](https://img.shields.io/cocoapods/v/CertificateSigningRequest.svg?style=flat)](https://cocoapods.org/pods/CertificateSigningRequest)\n[![License](https://img.shields.io/badge/license-GPL%202.0-green.svg)][license-link]\n\nGenerate a certificate signing request (CSR) in iOS/macOS using Swift.\n\n[license-link]: LICENSE\n\n## iOS\nSupports RSA (key size: 512, 1024, 2048) and EC inside/outside of secure enclave (iOS only supports 256 bit keys for now), SHA1, SHA256, and SHA512. \n\n## macOS\nSupports RSA (key size: 1024, 2048) and EC inside/outside of secure enclave, SHA1, SHA256, and SHA512. \n\n## Usage\n\nTo use, follow the following steps:\n\n1. Generate your publicKey/privateKey pair. This can be done using Keychain in iOS. An example can be found in the `generateKeysAndStoreInKeychain` function in the [testfile](https://github.com/cbaker6/CertificateSigningRequest/blob/d2cb683c4c5d081f85e810edf4984c36c5b9d252/Tests/CertificateSigningRequestTests/CertificateSigningRequestTests.swift#L547).\n2.  Get your publicKey in bits by querying it from the iOS keychain using `String(kSecReturnData): true` in your query. For example:\n\n```swift\n//Set block size\nlet keyBlockSize = SecKeyGetBlockSize(publicKey)\n//Ask keychain to provide the publicKey in bits\nlet query: [String: Any] = [\n    String(kSecClass): kSecClassKey,\n    String(kSecAttrKeyType): algorithm.secKeyAttrType,\n    String(kSecAttrApplicationTag): tagPublic.data(using: .utf8)!,\n    String(kSecReturnData): true\n]\n\nvar tempPublicKeyBits:CFTypeRef?\nvar _ = SecItemCopyMatching(query as CFDictionary, \u0026tempPublicKeyBits)\n\nguard let keyBits = tempPublicKeyBits as? Data else {\n    return (nil,nil)\n}\n```\n3. Initialize the `CertificateSigningRequest` using `KeyAlgorithm.ec` or `KeyAlgorithm.rsa` (an example of how to do can be found in the [test](https://github.com/cbaker6/CertificateSigningRequest/blob/d2cb683c4c5d081f85e810edf4984c36c5b9d252/Tests/CertificateSigningRequestTests/CertificateSigningRequestTests.swift#L116) file. Below are 3 possible ways to initialize: \n```swift \nlet csr = CertificateSigningRequest() //CSR with no fields, will use defaults of an RSA key with sha512\nlet algorithm = KeyAlgorithm.ec(signatureType: .sha256)\nlet csr = CertificateSigningRequest(keyAlgorithm: algorithm) //CSR with a specific key \nlet csr = CertificateSigningRequest(commonName: String?, organizationName: String?, organizationUnitName: String?, countryName: String?, stateOrProvinceName: String?, localityName: String?, emailAddress: String?, description: String?, keyAlgorithm: algorithm) //Define any field you want in your CSR along with the key algorithm\n```\n\n4. Then simply build your CSR using your publicKey(bits) and privateKey using:\n ```swift \n let builtCSR = csr.buildCSRAndReturnString(publicKeyBits, privateKey: privateKey)\n //Or if you want `CertificateSigningRequest` to verify the signature after building, pass in your publicKey to the same method:\n let builtCSR = csr.buildCSRAndReturnString(publicKeyBits, privateKey: privateKey, publicKey: publicKey)\n ``` \n- Two other methods are available depending on your needs.\n- To get CSR without header and footer info use: `let builtCSR = csr.buildAndEncodeDataAsString(publicKeyBits, privateKey: privateKey)`.\n- To get CSR as Data use: `let builtCSR = csr.build(publicKeyBits, privateKey: privateKey)`.\n\nNote:\n\nYou can test if your CSRs are correct by running and setting a break point the [test file](https://github.com/cbaker6/CertificateSigningRequest/blob/d2cb683c4c5d081f85e810edf4984c36c5b9d252/Tests/CertificateSigningRequestTests/CertificateSigningRequestTests.swift#L127). You can also let all test run and test the different CSR's. The output of the CSR will print in the console window. You can output the CSR's and your own app by printing to the console and check if they are created correctly by pasting them here: https://redkestrel.co.uk/products/decoder/ or by using openssl.\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first. An example certificate from this framework is below:\n\n```\n-----BEGIN CERTIFICATE REQUEST-----\nMIIBYTCCAQcCAQAwgaQxCzAJBgNVBAYMAlVTMQswCQYDVQQIDAJLWTENMAsGA1UE\nBwwEVGVzdDENMAsGA1UECgwEVGVzdDENMAsGA1UECwwEVGVzdDEnMCUGA1UEAwwe\nQ2VydGlmaWNhdGVTaWduaW5nUmVxdWVzdCBUZXN0MSIwIAYJKoZIhvcNAQkBDBNu\nZXRyZWNvbkBjcy51a3kuZWR1MQ4wDAYDVQQNDAVoZWxsbzBZMBMGByqGSM49AgEG\nCCqGSM49AwEHA0IABN5Wp7zEAVkffuqmkC22j3mOCJalTo2Beff23N8Bv7sZ0iTM\nAdqeeF+A1fAO5yUwykbTYhAyNiwkT82jtOy09xKgADAKBggqhkjOPQQDAgNIADBF\nAiEAt85IAQ9kOptiplqYkLyRz4is/uB4DffNpWuP9EUJY74CIHtjMZ6QRwY1zPGI\nbXC5eX6Kpv5QLfvR6xX7Xqaoy6Ai\n-----END CERTIFICATE REQUEST-----\n```\n\nYou can test if the CSR was created correctly here: [https://redkestrel.co.uk/products/decoder/](https://redkestrel.co.uk/products/decoder/)\n\n## Requirements\n- iOS 10+\n- mac OS 10.13+\n\n## Installation\n\n### Swift Package Manager (SPM) - Option 1\nCertificateSigningRequest can be installed via SPM. Open an existing project or create a new Xcode project and navigate to `File \u003e Swift Packages \u003e Add Package Dependency`. Enter the url `https://github.com/cbaker6/CertificateSigningRequest.git` and tap `Next`. Choose the main branch, and on the next screen, check off the package.\n\n### Cocoapods - Option 2\nCertificateSigningRequest is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'CertificateSigningRequest'\n```\n\n### Embedded Framework - Option 3\nIf you would like to use as a framework, clone and build the project, look under frameworks, and drag \"CertificateSigningRequest.framework\" into \"Frameworks\" section of your project, \"check copy if needed\".\n\n- In your project Targets, click on \"General\", make sure \"CertificateSigningRequest.framework\" shows up under \"Embedded Binaries\" and it should automatically appear in \"Linked Frameworks and Libraries\"\n- Then, simply place `import CertificateSigningRequest` at the top of any file that needs the framework.\n\n## Author\n\ncbaker6, coreyearleon@icloud.com\n\n## License\nComponents of CertificateSigningRequest was originally in [ios-csr](https://github.com/ateska/ios-csr) by Ales Teska written in Objective-C and ported by the author of CertificateSigningRequest to Swift. Therefore CertificateSigningRequest has the same GPLv2 license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbaker6%2Fcertificatesigningrequest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcbaker6%2Fcertificatesigningrequest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbaker6%2Fcertificatesigningrequest/lists"}