Bom dia Douglas.
Você tem o certificar? .der?
Att,
2013/5/3 Douglas Alípio <douglas.alipio@gmail.com>
Seguinte, eu tenho uma chave pública gerada de um servidor Rails. Meu objetivo é criptografar dados através do RSA. Por exemplo,--Recupero o arquivo public-key.pemString filePath = getFilesDir().getAbsolutePath();File file = new File(filePath, "public-key.pem");FileInputStream fileInput = new FileInputStream(file);De acordo com esse link para criptografar os dados seria dessa forma:Obtendo a publicKey:DataInputStream dis = new DataInputStream(fileInput);byte[] keyBytes = new byte[fileInput.available()];dis.readFully(keyBytes);dis.close();X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);KeyFactory keyFactory = KeyFactory.getInstance("RSA");keyFactory.generatePublic(spec);------ Erro acontece nesta linha.
Criptografando o dado:byte[] encryptedBytes;Cipher cipher = Cipher.getInstance("RSA");PublicKey publicKey = getPublicKey();cipher.init(Cipher.ENCRYPT_MODE, publicKey);encryptedBytes = cipher.doFinal(plain.getBytes());String encrypted = new String(encryptedBytes);Estou recebendo esta exceptionjava.security.spec.InvalidKeySpecException: java.io.IOException: cannot recognise object in streamJá testei com várias outras chaves e dá o mesmo erro...--
Atenciosamente,
Douglas Alípio Mesquita
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
"Give Peace a Chance"
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.






0 comentários:
Postar um comentário