How can I construct a java.security.PublicKey object from a base64 encoded string?

后端 未结 5 1862
生来不讨喜
生来不讨喜 2020-11-30 02:40

I have a bse64encoded string Public key from external source (Android Store) and I need to use it to verify signed content. How can I convert the string into an instance of

5条回答
  •  孤独总比滥情好
    2020-11-30 03:13

    Try this....

    PublicKey getPublicKey(byte[] encodedKey) throws NoSuchAlgorithmException, InvalidKeySpecException
    {
        KeyFactory factory = KeyFactory.getInstance("RSA");
        X509EncodedKeySpec encodedKeySpec = new X509EncodedKeySpec(encodedKey);
        return factory.generatePublic(encodedKeySpec);
    }
    

提交回复
热议问题