Code example for X509EncodedKeySpec

0
     */ 
    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);
        } 
    } 
 
    /** 
     * Verifies that the signature from the server matches the computed 
     * signature on the data.  Returns true if the data is correctly signed. 
     *