How to convert Byte array to PrivateKey or PublicKey type?

If you have a byte[] representing the output of getEncoded() on a key, you can use KeyFactory to turn that back into a PublicKey object or a PrivateKey object. byte[] privateKeyBytes; byte[] publicKeyBytes; KeyFactory kf = KeyFactory.getInstance(“RSA”); // or “EC” or whatever PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(privateKeyBytes)); PublicKey publicKey = kf.generatePublic(new X509EncodedKeySpec(publicKeyBytes));

How to load the RSA public key from file in C#

You can create an RSACryptoServiceProvider from a PEM file using the following class (GetRSAProviderFromPemFile method). Warning: Don’t just copy code from StackOverflow without verification! Especially not crypto code! This code has bugs (see comments). You may want to write and run tests before using this in production (if you really have no better option). I …

Read more

X.509: Private / Public Key

The basics command line steps to generate a private and public key using OpenSSL are as follow openssl genrsa -out private.key 1024 openssl req -new -x509 -key private.key -out publickey.cer -days 365 openssl pkcs12 -export -out public_privatekey.pfx -inkey private.key -in publickey.cer Step 1 – generates a private key Step 2 – creates a X509 certificate …

Read more

How to let TortoiseHg (Mercurial) on Windows use the Private Key file generated (by Puttygen)?

Either add the following to the [ui]-section of the mercurial.ini in your home directory (assuming your key is in “C:\Users\UserName\mykey.ppk”): [ui] ssh = tortoiseplink.exe -ssh -i “C:\Users\UserName\mykey.ppk” or use Pageant, found in the TortoiseHg installation path (e.g. C:\Program Files\TortoiseHg\Pageant.exe). Start it, double click the taskbar-icon that appears, and add the .ppk-file.