code: public static PublicKey generatePublicKey(String encodedPublicKey) {
          try {
              byte[] decodedKey = Base64.decode(encodedPublicKey);
              KeyFactory keyFactory = KeyFactory.getInstance(KEY_FACTORY_ALGORITHM);
              return keyFactory.generatePublic(new X509EncodedKeySpec(decodedKey));
          } catch (NoSuchAlgorithmException e) {
              throw new RuntimeException(e);
          } catch (InvalidKeySpecException e) {
              Log.e(TAG, "Invalid key specification.");
              throw new IllegalArgumentException(e);
          } catch (Base64DecoderException e) {
              Log.e(TAG, "Base64 decoding failed.");
              throw new IllegalArgumentException(e);
          }
      }
docs: Generates a PublicKey instance from a string containing the
  Base64-encoded public key.
  
  @param encodedPublicKey Base64-encoded public key
  @throws IllegalArgumentException if encodedPublicKey is invalid