Java tutorial
//package com.java2s; import java.security.KeyFactory; import java.security.PrivateKey; import java.security.spec.PKCS8EncodedKeySpec; import org.apache.commons.codec.binary.Base64; public class Main { public static PrivateKey getPrivateKey(String key) { try { Base64 base64_decoder = new Base64(); byte[] byteKey = base64_decoder.decode(key.getBytes()); // , // Base64.DEFAULT); PKCS8EncodedKeySpec X509privateKey = new PKCS8EncodedKeySpec(byteKey); KeyFactory kf = KeyFactory.getInstance("RSA"); return kf.generatePrivate(X509privateKey); } catch (Exception e) { e.printStackTrace(); } return null; } }