Home How to decode password by base64_decode in Android
Reply: 2

How to decode password by base64_decode in Android

Unnati
1#
Unnati Published in 2018-02-14 09:21:13Z

My password come from database and it's encoded, so how can I decode it in Android side?

SharedPreferences preferences = getSharedPreferences("mypref", MODE_PRIVATE);
id = preferences.getString("id", "");
password=preferences.getString("password","");

password is encoded by base64_encode.

I want to decode that password.

I use this:

byte[] decodePassword;
decodePassword= Base64.decode(password, Base64.DEFAULT);

but it didn't work.

ヅ fix
2#
ヅ fix Reply to 2018-02-14 09:39:57Z

try this

byte[] decodePassword;
decodePassword= Base64.decode(password, Base64.DEFAULT);
String your_password = new String(decodePassword, StandardCharsets.UTF_8);
Nikhil Sawant
3#
Nikhil Sawant Reply to 2018-02-14 09:28:10Z

Try Using this method.

public static String dec(String input_text,String secret_key) {
        try {
            AlgorithmParameterSpec paramSpec = new IvParameterSpec(secret_key
                    .getBytes());
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            SecretKeySpec key  = new SecretKeySpec(secret_key.getBytes(), "AES");
            cipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
            byte[] output = Base64.decodeBase64(input_text.getBytes());
            byte[] decrypted = cipher.doFinal(output);
            return new String(decrypted);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.403431 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO