Monday, December 26, 2011

[android-developers] File encryption using AES

Hi all,

I am trying the AES file encryption on android, but at the runtime it
is giving one Exception,i am not able to find out any solution for
this.

My code for encryption is :
i have already initialized the file as

File file = new File("/mnt/sdcard/a.txt");

public void encrypt(File file,String aesKey) throws Exception
{
try
{
byte[] byteKey = aesKey.getBytes("UTF8");
KeySpec ks = new SecretKeySpec(byteKey,"AES");
SecretKeyFactory skf = SecretKeyFactory.getInstance("AES"); //
Giving Exception at this line
SecretKey sk = skf.generateSecret(ks);
aspec = new IvParameterSpec(ivector);
encCipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
encCipher.init(Cipher.ENCRYPT_MODE, sk);
in = new FileInputStream(file);
AlertDialog.Builder builder = new AlertDialog.Builder(null);
builder.setMessage("you are in middle of encrypt function");
AlertDialog alert = builder.create();
FileOutputStream fout = new FileOutputStream("/mnt/sdcard/a.txt");
out = new CipherOutputStream(fout,encCipher);
int num = 0;
while((num = in.read(buffer)) >=0)
{
out.write(buffer, 0, num);

}

out.close();
}

Exception is : java.security.NoSuchAlgorithmException :
SecretKeyFactory AES implementation not found.


Please help and rectify the code or if possible give a working code
for File encryption using AES. i don't know why this implementation is
not there.

any help is appreciated.

Thanks

--
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