Giter Club home page Giter Club logo

csharp-easy-rsa-pem's Introduction

CSharp-easy-RSA-PEM

License: GNU GENERAL PUBLIC LICENSE v3 Author: Christoffer Järnåker Description: Class library with sample app to load and save PEM encoded keys into RSACryptoServiceProvider.

This library was made to facilitate an easy way to interact with PEM encoded certificates from C# on Windows. I made this as this seems to be an ongoing issue for C# developers, cause by the fact that MS apparently wants us to only save our keys in XML format. Well, that doesn't work that well if you want your keys to be used outside of Windows, and you can't use keys made in the most commonly available format: ASN.1 PEM encoded, e.g. what you usually get out of OpenSSL and such likes. It's made up from bits and pieces of code found on the net, mixed together with my own, so please look at the end of this doc for some sources and credits.

Example on how to use on private and public keys generated by OpenSSL and saved in PEM format (most common):

      // Load private key. This is stored in RSA format.
      string priv = File.ReadAllText("keys\\private.rsa.key");
      RSACryptoServiceProvider privc = Crypto.DecodeRsaPrivateKey(priv);

      // Load public key. This is stored in X.509 format
      string publ = File.ReadAllText("keys\\public.rsa.key");
      RSACryptoServiceProvider publc = Crypto.DecodeX509PublicKey(publ);

      // Encrypt with public key, decrypt with private.
      string supersecret = Crypto.EncryptString("Hello", publc);
      string decodesecret = Crypto.DecryptString(supersecret, privc);

Sources and credits Some sources are simply meantioned here though I don't use any of its code. But inspiration and help on the path of understanding is also worth mentioning ;)

Thanks Jeffrey Walton for the awsome implementation of AsnKeyBuilder and AsnKeyParser. He also provides an great in depth article on what keys in what formats fits where. Really good base for understanding therelation between RSA, PKCS #8, X.509 and ASN.1. http://www.codeproject.com/Articles/25487/Cryptographic-Interoperability-Keys

Thanks Mario Majčica for showing the interaction between certificates and keys http://www.codeproject.com/Articles/162194/Certificates-to-DB-and-Back

Thanks to Iridium and abasan for showing the basic structure of the RSA PEM format. http://stackoverflow.com/questions/23734792/c-sharp-export-private-public-rsa-key-from-rsacryptoserviceprovider-to-pem-strin

Thanks Michel Gallant for a great implementation. I learned a lot from your code. http://www.jensign.com/opensslkey/opensslkey.cs

csharp-easy-rsa-pem's People

Contributors

jrnker avatar nothing4you avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.