Convert RSA to PEM file

How can I convert the RSA public key: 109120132967399429278860960508995541528237502902798129123468757937266291492576446330739696001110 6039072308886100726558188253585034290 57592827629436413108566029093628 2126359538366865626758497206207862794310902180176810615217550567108238764764442605581471797071 19674283982419152118103759076030616683978566631413

to * .pem file?

+3
source share
4 answers

The pem file is not really a format, and various objects can be stored in files called pem. Most often, these files contain either an X509 certificate with base64 encoding or a private key object with base64 encoding.

, X509, , , . . , .

PS. RSA . ?

+6

- base64 hex. . script ( PHP), :

<?php

$list = array_slice($argv, 1);

foreach ($list as $file) {
    $hex = str_replace("\n", "", file_get_contents($file));
    $pem = str_replace(".hex", ".pem", $file);
    $b64 = base64_encode(hex2bin($hex));
    $fd = fopen($pem, 'w');
    fprintf($fd, "-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY----\n", implode("\n", str_split($b64, 64)));
    fclose($fd);
}

.hex, ".pem". :

PHP .php *.hex
+1

OpenSSL. , DER, DER PEM.

openssl x509 -inform der -in input.der -out output.pem

If you are not sure if the DER key is formatted correctly (ASN.1), try this tool to parse your input file,

0
source

use putty programs, PuTTYgen does this conversion

-1
source

Source: https://habr.com/ru/post/1781139/


All Articles