An importer and exporter for the ASN.1 DER encoding of an RSA public key.
This project includes the RSAPublicKeyImporter and RSAPublicKeyExporter module, written in Swift and featuring an importer and exporter that can be used for converting the ASN.1 DER encoding of an RSA public key from and to a format typically used by tools and programming languages outside the Apple ecosystem (e.g. OpenSSL, Java, PHP and Perl).
Note that built-in support for both encoding formats is actually quite solid in the Apple ecosystem, meaning that the RSAPublicKeyImporter module is kind of redundant in that sense. However, this module can be used for testing the RSAPublicKeyExporter module that has a real-world application (or at least as long as Apple has no built-in support for exporting RSA public keys). In any case, both modules are considered a basic example of how the SimpleASN1Reader and SimpleASN1Writer module in the simple-asn1-reader-writer project can be used.
Usage
rsa-public-key-importer-exporter is a SwiftPM project and can be built, tested and run using these commands:
$ swift build
$ swift test
$ swift run RSAPublicKeyImportExportDemo
To depend on rsa-public-key-importer-exporter, put the following in the dependencies of your Package.swift:
RSA Public Key Importer and Exporter
An importer and exporter for the ASN.1 DER encoding of an RSA public key.
This project includes the
RSAPublicKeyImporterandRSAPublicKeyExportermodule, written in Swift and featuring an importer and exporter that can be used for converting the ASN.1 DER encoding of an RSA public key from and to a format typically used by tools and programming languages outside the Apple ecosystem (e.g. OpenSSL, Java, PHP and Perl).Note that built-in support for both encoding formats is actually quite solid in the Apple ecosystem, meaning that the
RSAPublicKeyImportermodule is kind of redundant in that sense. However, this module can be used for testing theRSAPublicKeyExportermodule that has a real-world application (or at least as long as Apple has no built-in support for exporting RSA public keys). In any case, both modules are considered a basic example of how theSimpleASN1ReaderandSimpleASN1Writermodule in the simple-asn1-reader-writer project can be used.Usage
rsa-public-key-importer-exporteris a SwiftPM project and can be built, tested and run using these commands:To depend on
rsa-public-key-importer-exporter, put the following in thedependenciesof yourPackage.swift:Code Examples:
Using the RSAPublicKeyImporter and RSAPublicKeyExporter Together
Create a public key (for example by using OpenSSL):
Extract the Base64 encoded DER encoding from the
key.pemfile, paste it in this file (or simply keep the example key unchanged) and run the demo:Expected output:
Dependencies
rsa-public-key-importer-exporterdepends on the following:simple-asn1-reader-writer, version 0.1.0 or better.Resources
A Layman’s Guide to a Subset of ASN.1, BER, and DER
X.690 (ASN.1 encoding formats: BER, DER and CER)
RFC 5280 (X.509 v3)
RFC 8017 (PKCS #1 v2.2)
License
rsa-public-key-importer-exporteris licensed under the MIT License. See LICENSE for details.