/*
 public static PublicKey readPublicKey(String filenameDer) throws Exception
 {
   byte[] keyBytes = readAllBytes(filenameDer);
   return readPublicKey(keyBytes);
 }*/
 public static PublicKey readPublicKey(byte[] keyBytes) throws Exception {
   KeyFactory keyFactory = newKeyFactory();
   X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
   return keyFactory.generatePublic(spec);
 }
 private static KeyFactory newKeyFactory() throws Exception {
   return KeyFactory.getInstance(KEY_ALGORITHM);
 }
  /*public static PrivateKey readPrivateKey(String filenameDer) throws Exception
  {
      byte[] keyBytes = readAllBytes(filenameDer);
    logger.debug("Key = " +  Hex.encodeHexString(keyBytes));
    return readPrivateKey(keyBytes);
  }*/
  public static PrivateKey readPrivateKey(byte[] keyBytes) throws Exception {

    KeyFactory keyFactory = newKeyFactory();
    PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
    return keyFactory.generatePrivate(spec);
  }