Android: Public Key initialization

view full story

http://stackoverflow.com – I want to initialize a PublicKey with a String such as 23441AB…2583DA== PublicKey publicKey=null; Cipher publicKeyCipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING"); publicKeyCipher.init(Cipher.ENCRYPT_MODE, publicKey); When I pass an empty key I get the following exception: java.security.InvalidKeyException: unknown key type passed to RSA Even if I pass a Key publicKey, says that the key type is unknown. I have seen that the proper way to initialize a PublicKey is: kpg = KeyPairGenerator.getInstance("RSA"); kpg.initialize(1024); kp = kpg.genKeyPair(); publicKey = kp.getPublic() (HowTos)