Android AES Encrypt encryptedPassword(String key, String userData)

Here you can find the source of encryptedPassword(String key, String userData)

Description

encrypted Password

Declaration

public static String encryptedPassword(String key, String userData) 

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 ENCODING = "ISO-8859-1";

    public static String encryptedPassword(String key, String userData) {
        String encryptedUserData = "";
        try {//w w  w.  jav a2 s  . c  o  m

            // Create key and cipher
            Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
            Cipher cipher = Cipher.getInstance("AES");

            // encrypt the text
            cipher.init(Cipher.ENCRYPT_MODE, aesKey);
            byte[] encrypted = cipher.doFinal(userData.getBytes());
            encryptedUserData = new String(encrypted, ENCODING);

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

Related

  1. aesEncode(String seed, String cleartext)
  2. encrypt(byte[] raw, byte[] clear)
  3. encrypt(Context context, String text)
  4. encrypt(Context context, String text)
  5. encryptedData(String userkey, String userData)
  6. generateEncryptionSecret()
  7. encode(String seed, String cleartext)