Convert::SSH2 - Convert SSH2 RSA keys to other formats
Version 0.01
use 5.010; use Convert::SSH2; my $converter = Convert::SSH2->new('~/.ssh/id_rsa.pub'); # Automatically calls parse() # Use default PKCS#1 format say $converter->format_output(); $converter->write('/my/pub/key.pem');
This library converts SSH2 style RSA public keys to other representations like PKCS#1. This is useful if you want to use these public keys with other Perl cryptography libraries like Crypt::RSA or Crypt::OpenSSL::RSA.
Required. Read-only. The key material. Attempts to be DWIMish. If this is a file path, it will be used to load the file contents into memory. If it's a buffer, it will use the buffer contents.
Read-only. The output format. Current supports:
pkcs1
This format looks like
-----BEGIN RSA PUBLIC KEY----- ... -----END RSA PUBLIC KEY-----
pkcs8
-----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY-----
You can add your own format by implementing a Convert::SSH2::Format::Base module.
Generally, errors are fatal. Use Try::Tiny if you want more graceful error handling.
Constructor. Takes any of the attributes as arguments. You may optionally call new with either a buffer or a path, and the class will assume that it is the key material.
key
The object automatically attempts to parse key data after instantiation.
This method takes the Base64 encoded portion of the SSH key, decodes it, and then converts the data inside of it into three components: the id string ('ssh-rsa'), the public exponent ('e'), and the modulus ('n'). By default it looks for the Base64 data inside the instantiated object, but you can optionally pass in a Base64 string.
It uses Math::BigInt to hold large integers such as 'n' or 'e'. If you don't have libgmp installed, it will fall back to pure perl automatically, but there will be a speed penalty.
libgmp
Returns a true value on success.
Using a subclass of Convert::SSH2::Format::Base, generate a representation of the SSH2 key.
Returns a formatted string.
Convenience method to write a formatted key representation to a file.
Expects a pathname. Automatically calls format_output() if necessary. If the output format has been generated already, it uses a cached version.
format_output()
Mark Allen, <mrallen1 at yahoo.com>
<mrallen1 at yahoo.com>
Please report any bugs or feature requests to bug-convert-ssh2 at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Convert-SSH2. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-convert-ssh2 at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Convert::SSH2
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Convert-SSH2
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Convert-SSH2
CPAN Ratings
http://cpanratings.perl.org/d/Convert-SSH2
MetaCPAN
https://metacpan.org/dist/Convert-SSH2
Git Hub
https://github.com/mrallen1/Convert-SSH2
Convert::SSH2::Format::Base, Convert::SSH2::Format::PKCS1
Converting OpenSSH public keys
Mark Cavage
Copyright 2012 Mark Allen.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Convert::SSH2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Convert::SSH2
CPAN shell
perl -MCPAN -e shell install Convert::SSH2
For more information on module installation, please visit the detailed CPAN module installation guide.