You seem to be saving the unencrypted username and password to the editor:
byte[ ] superSecretKeyBytes = Base64.decode(pass);
byte[] key = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6 };
for (int i = 0; i < superSecretKeyBytes.length && i < key.length; i++) {
key[i] = superSecretKeyBytes[i];
myEditor.putString("PASSWORD_KEY", pass);
}
To be completely honest, I don't see why you're doing ANY of that. What you're actually doing seems really unnecessary, since you're decoding it into a byte array, creating a fixed-amount byte array, looping through the decoded array, and replacing the created fixed-amount array's data with the decoded one, and then adding the un-changed String password to the editor (which you're doing far too many times, also, btw). And I'm pretty sure that's not what you're trying to do.
I believe what you're trying to do there is actually encrypt it, but you never got around to it, so let's try this:
First, your key should be a static variable as if that changes, it will no longer be able to encrypt/decrypt appropriately.
byte[] key = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6 };
Now to encrypt the password, based on what you already have, call your encrypt method based on your secret key (in this case: key) and the String you want to encrypt (in this case: pass):
String encryptedPassword = encrypt(pass, key);
Now encryptedPassword contains the Base64 encrypted form of your password based on the key you entered. Now all that's left to do is save the encrypted form of your password with the editor, instead of the unencrypted form like you were doing previously.
myEditor.putString("PASSWORD_KEY", encryptedPassword);
So now when you call myEditor.commit(), you'll store the encrypted form.
Here's the edited onClick method from the first source file for both username and password encryption. I didn't look at your decryption part, but you should be able to figure it out based on what I gave you:
public void onClick(View arg0) {
user=rName.getText().toString().trim();
pass=rPwd.getText().toString().trim();
if(arg0==regBttn){
if((user.length()!=0))
{
if((pass.length()!=0))
{
sp=getSharedPreferences("AccessApp",MODE_WORLD_WRITEABLE);
Editor myEditor=sp.edit();
byte[] key = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6 };
try {
String encryptedUser = encrypt(user, key);
myEditor.putString("USERNAME_KEY", encryptedUser);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
String encryptedPass = encrypt(pass, key);
myEditor.putString("PASSWORD_KEY", encryptedPass);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
myEditor.commit();
Toast.makeText(this, "Registration is successfull",10000).show();
i=new Intent(this,AccessApp.class);
startActivity(i);
}
else
{
Toast.makeText(this, "Please Enter password", 10000).show();
}
}
else{
Toast.makeText(this,"Please Enter Username",10000).show();
}
}
else if(arg0==rtnBttn){
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("Exit");
builder.setMessage("Do you want to exit");
builder.setCancelable(false);
builder.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
finish();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
arg0.cancel();
}
});
AlertDialog alert=builder.create();
alert.show();
}
}
Hope it helps~