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

后端 未结 5 1858
生来不讨喜
生来不讨喜 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:00

    Ok for grins ... try this

    • base64 decode the key data to get a byte array (byte[])
    • Create a new X509EncodedKeySpec using the byte array
    • Get an instance of KeyFactory using KeyFactory.getInstance("RSA") assuming RSA here
    • call the method generatePublic(KeySpec) with the X509EncodedKeySpec
    • Result /should/ be a public key for your usage.

提交回复
热议问题