/pem-utils

Unity UPM C# utility library for working with PEM files with DER/ASN.1 encoding

Primary LanguageC#Apache License 2.0Apache-2.0

PEM-utils

Build status openupm

Unity C# utility library for working with PEM files with DER/ASN.1 encoding.

This project has 2 separate libraries:

  • DerConverter - for converting ASN.1 syntax from/to binary data
  • PemUtils - builds on top of DerConverter for reading/writing RSAParameters from/to a PEM formatted file

PEM files are commonly used to exchange public or private key data.

Currently files with these headers are supported:

  • ----- BEGIN PUBLIC KEY ----- / ----- END PUBLIC KEY -----
  • ----- BEGIN RSA PUBLIC KEY ----- / ----- END RSA PUBLIC KEY ----- (Read Only)
  • ----- BEGIN RSA PRIVATE KEY ----- / ----- END RSA PRIVATE KEY -----

Install

This is a UPM and can be installed from OpenUPM or as a GIT repositoory.

Usage

Reading

using (var stream = File.OpenRead(path))
using (var reader = new PemReader(stream))
{
    var rsaParameters = reader.ReadRsaKey();
    // ...
}

Writing

using (var stream = File.Create(path))
using (var writer = new PemWriter(stream))
{
    // ...
    writer.WritePublicKey(rsaParameters);
}