{"id":15645878,"url":"https://github.com/stefh/openssl-x509certificate2-provider","last_synced_at":"2025-04-10T01:14:33.699Z","repository":{"id":65332050,"uuid":"97369692","full_name":"StefH/OpenSSL-X509Certificate2-Provider","owner":"StefH","description":"Parses OpenSSL public and private key components and returns a X509Certificate2 with RSACryptoServiceProvider. Based on opensslkey","archived":false,"fork":false,"pushed_at":"2021-06-26T06:43:01.000Z","size":2232,"stargazers_count":54,"open_issues_count":9,"forks_count":14,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-10T01:14:21.393Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StefH.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-07-16T08:14:27.000Z","updated_at":"2025-02-18T20:06:11.000Z","dependencies_parsed_at":"2023-01-17T13:15:30.582Z","dependency_job_id":null,"html_url":"https://github.com/StefH/OpenSSL-X509Certificate2-Provider","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefH%2FOpenSSL-X509Certificate2-Provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefH%2FOpenSSL-X509Certificate2-Provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefH%2FOpenSSL-X509Certificate2-Provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefH%2FOpenSSL-X509Certificate2-Provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StefH","download_url":"https://codeload.github.com/StefH/OpenSSL-X509Certificate2-Provider/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137891,"owners_count":21053775,"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","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":[],"created_at":"2024-10-03T12:10:27.525Z","updated_at":"2025-04-10T01:14:33.680Z","avatar_url":"https://github.com/StefH.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenSSL X509Certificate2 Provider\nParses OpenSSL public and private key components and returns a **X509Certificate2** with **RSA/RSACryptoServiceProvider**. (Based on [http://www.jensign.com/opensslkey/opensslkey.cs (Archive Link)](https://web.archive.org/web/20171205121514/http://www.jensign.com/opensslkey/opensslkey.cs))\n\n| Project | NuGet |\n| ------- | ----- |\n| OpenSSL.PrivateKeyDecoder | [![NuGet Badge](https://buildstats.info/nuget/OpenSSL.PrivateKeyDecoder)](https://www.nuget.org/packages/OpenSSL.PrivateKeyDecoder) |\n| OpenSSL.PublicKeyDecoder | [![NuGet Badge](https://buildstats.info/nuget/OpenSSL.PublicKeyDecoder)](https://www.nuget.org/packages/OpenSSL.PublicKeyDecoder) |\n| OpenSSL.X509Certificate2.Provider | [![NuGet Badge](https://buildstats.info/nuget/OpenSSL.X509Certificate2.Provider)](https://www.nuget.org/packages/OpenSSL.X509Certificate2.Provider) |\n\nSupport for the following frameworks:\n* .NET 2.0\n* .NET 3.5\n* .NET 4.5 and up\n* .NET Standard 1.3 (also NET Core 1.1)\n* .NET Standard 2.0 (also NET Core 2.0 and 2.1)\n\nSupport for decoding `RSA Private Key`, `Private Key` and `Public Key`.\n\n## Example\n\n### Generate public certificate + privatekey\nGenerate public certificate + privatekey using:\n```\nopenssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout private.key -out certificate_pub.crt\n```\n\n### Code example 1 - decode private key into RSAParameters\nIf you just want to decode the private key into RSAParameters, use the following code:\n```csharp\nstring privateKeyText = File.ReadAllText(\"private.key\");\n\nIOpenSSLPrivateKeyDecoder decoder = new OpenSSLPrivateKeyDecoder();\nRSAParameters parameters = decoder.DecodeParameters(privateKeyText);\n\n// do something with the parameters ...\n```\n\n### Code example 2 - decode private key into a RSACryptoServiceProvider\nIf you want to decode the private key into a RSACryptoServiceProvider, use the following code:\n```csharp\nstring privateKeyText = File.ReadAllText(\"private.key\");\n\nIOpenSSLPrivateKeyDecoder decoder = new OpenSSLPrivateKeyDecoder();\nRSACryptoServiceProvider cryptoServiceProvider = decoder.Decode(privateKeyText);\n\n// Example: sign the data\nbyte[] hello = new UTF8Encoding().GetBytes(\"Hello World\");\nbyte[] hashValue = cryptoServiceProvider.SignData(hello, CryptoConfig.MapNameToOID(\"SHA256\"));\n\n// Example: use the PrivateKey from above for signing a JWT token using Jose.Jwt:\nstring token = Jose.JWT.Encode(payload, cryptoServiceProvider, JwsAlgorithm.RS256);\n```\n\n### Code example 3 - Create a X509 certificate and add private key\n```csharp\nstring certificateText = File.ReadAllText(\"certificate_pub.crt\");\nstring privateKeyText = File.ReadAllText(\"private.key\");\n\nICertificateProvider provider = new CertificateFromFileProvider(certificateText, privateKeyText);\nX509Certificate2 certificate = provider.Certificate;\n\n// Example: use the PrivateKey from the certificate above for signing a JWT token using Jose.Jwt:\nstring token = Jose.JWT.Encode(payload, certificate.PrivateKey, JwsAlgorithm.RS256);\n```\n\n### Code example 4 - decode openssl RSA public key into RSAParameters\nIf you just want to decode the rsa public key into RSAParameters, use the following code:\n\nExport the public key from the private key with openssl\n```\nopenssl rsa -in private.key -out public.key -pubout\n```\n\n```csharp\nstring publicKeyText = File.ReadAllText(\"public.key\");\n\nIOpenSSLPublicKeyDecoder decoder = new OpenSSLPublicKeyDecoder();\nRSAParameters parameters = decoder.DecodeParameters(publicKeyText);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefh%2Fopenssl-x509certificate2-provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefh%2Fopenssl-x509certificate2-provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefh%2Fopenssl-x509certificate2-provider/lists"}