AssetManager am = context.getAssets();
InputStream ins = null;
try {
ins = am.open("test.pem");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
// BASE64Decoder base64Decoder= new BASE64Decoder();
// byte[] buffer= base64Decoder.decodeBuffer(priKeyStr);
// PKCS8EncodedKeySpec keySpec= new PKCS8EncodedKeySpec(buffer);
// KeyFactory keyFactory= KeyFactory.getInstance("RSA");
// RSAPrivateKey privateKey= (RSAPrivateKey)
// keyFactory.generatePrivate(keySpec);
//
// int i = 0 ;
// i++;
PEMReader reader = new PEMReader(new InputStreamReader(ins),new PasswordFinder() {
@Override
public char[] getPassword() {
return KEYPASS.toCharArray();
}
});
KeyPair keyPair = (KeyPair) reader.readObject();
reader.close();
PublicKey key = keyPair.getPublic();
Log.i("pubk", key.toString());
PrivateKey prik = keyPair.getPrivate();
Log.i("prik", prik.toString());