ok thanks Nikolay ,i'll try the HTTPS ,but don't have a great idea
about this approach "HTTPS",can you please give me some examples or
tutorials.
thanks a lot.

2013/1/10, Nikolay Elenkov <nikolay.elen...@gmail.com>:
> On Thu, Jan 10, 2013 at 8:31 PM, Ines <belhouchet.i...@gmail.com> wrote:
>> i have some problems when i try to encrypt a string with a public key
>> stored
>> in res/raw thesis the encrypt method code:
>
>>
>>         // converts the String to a PublicKey instance
>>        byte[] keyBytes = Base64.decode(keyString.getBytes("utf-8"),
>> DEFAULT_KEYS_DIALER);
>>         X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
>>         KeyFactory keyFactory = KeyFactory.getInstance("RSA");
>>         PublicKey key = keyFactory.generatePublic(spec);
> ....
>>
>> and this's my public key stored in res/raw
>>
>>     -----BEGIN CERTIFICATE-----
>> MIIDuDCCAqACCQDxZX5jygcxvzANBgkqhkiG9w0BAQUFADCBnTELMAkGA1UEBhMC
>
> What you have is a certificate, not a public key. You are trying to parse it
> as
> a public key, that is why get an exception. Parse the certificate, then
> extract
> the public key from the resulting X509Cetificate if you must.
>
> However, using raw RSA is rarely a good idea. If you want to communicate
> securely with your server use standard HTTPS (SSL).
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to