Here you can find the source of getKey()
private static Key getKey()
//package com.java2s; //License from project: Apache License import java.io.*; import java.security.*; import java.security.spec.PKCS8EncodedKeySpec; public class Main { private static Key getKey() { try {//w w w . j av a2 s .c o m InputStream fis = ClassLoader.getSystemResourceAsStream("key.pk8"); if (fis == null) { throw new RuntimeException("Cannot find keyfile"); } try { // openssl pkcs8 -inform pem -outform der -topk8 -nocrypt -in key.pem -out key.pk8 return KeyFactory.getInstance("RSA") .generatePrivate(new PKCS8EncodedKeySpec(getByteArrayFromStream(fis))); } finally { fis.close(); } } catch (Exception e) { throw new RuntimeException(e); } } public static byte[] getByteArrayFromStream(InputStream is) throws IOException { byte[] b = new byte[10000]; int read; ByteArrayOutputStream out = new ByteArrayOutputStream(); while ((read = is.read(b, 0, b.length)) > 0) { out.write(b, 0, read); } return out.toByteArray(); } }