Monday, December 26, 2011

Re: [android-developers] File encryption using AES

On Tue, Dec 27, 2011 at 3:31 PM, Chander mourya <mohan.ck10@gmail.com> wrote:

> i implemented DES algorithm to encrypt a String it worked fine in that
> but while encrypting a file i have to ask user an Encryption key so at
> that time i am asking for a key and then i am converting it to byte
> array. but this SecretFactory not working this time can you explain
> and if possible can you edit this text by using a raw key?
>

You need to clarify what you are doing, but generally, you shouldn't be
asking the user for a key. You might ask them for a *passphrase* and
derive a key from that. On Android something like this will generate
a 256-bit AES key from the user supplied passphrase. 'Pass' is
the pasphrase and 'salt' are randomly generated bytes:


String pass = ...;
byte[] salt = ...;
int iterations = 1024;
int keylen = 256;

SecretKeyFactory.getInstance kf =
SecretKeyFactory.getInstance("PBEWITHSHAAND256BITAES-CBC-BC");
KeySpec keySpec = new PBEKeySpec(pass.toCharArray(), salt, iterations, keylen);
SecretKey sk = kf.generateSecret(keySpec);

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment