Android AES Decrypt decryptedData(String userkey, String encryptedData)

Here you can find the source of decryptedData(String userkey, String encryptedData)

Description

decrypted Data

Declaration

public static String decryptedData(String userkey, String encryptedData) 

Method Source Code

//package com.java2s;
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class Main {
    private static final String APP_KEY = "yourName";
    private static final String ENCODING = "ISO-8859-1";

    public static String decryptedData(String userkey, String encryptedData) {
        String decryptedUserData = "";
        try {//from  ww  w . ja v a  2 s  .c om
            String key = getAppPassCode(userkey);
            // Create key and cipher
            Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
            Cipher cipher = Cipher.getInstance("AES");
            // decrypt the text
            cipher.init(Cipher.DECRYPT_MODE, aesKey);
            byte[] userData = cipher.doFinal(encryptedData
                    .getBytes(ENCODING));
            decryptedUserData = new String(userData);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return decryptedUserData;
    }

    private static String getAppPassCode(String userPassCode) {
        String appPassCode = userPassCode;
        if (userPassCode.length() < 16) {
            appPassCode = appPassCode
                    + APP_KEY.substring(0,
                            (APP_KEY.length() - userPassCode.length()));
        }
        return appPassCode;
    }
}

Related

  1. decrypt(byte[] raw, byte[] encrypted)
  2. decrypt(Context context, String encrypted)
  3. decrypt(Context context, String encrypted)
  4. decode(String seed, String encrypted)
  5. decrypt(byte[] raw, byte[] encrypted)
  6. decryptedPassword(String key, String encryptedData)