Sample code for 30+ languages & platforms
Android™

Simple AES ECB Decryption

See more Encryption Examples

Decrypt 256-bit encrypted content.

Chilkat Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkCrypt2 crypt = new CkCrypt2();

    // Encrypted content (base64-encoded)
    String ct = "d/95VziAnUNKkpXr3dJBFcQqAEDWlDkc7EU2jLkYPxmr6PpLRJlgHos+/Uy28CvJsmztQ3JkJAMukVoj46QJ/7RMuqLb31cSKd1ZvMzx9J9b6q0EkmPJcSfBhf2x7v5Qvq3lz1EIH7RM61cDGf+g9p4lt6FtU2MzCqtYD+Vr29voCn5WU1CnXmks64RrbyDA1DDHOx2deJ4Kn68+KoPM9tAw9kbf4HApL1nJYU3Mfzl+MnuHuB2kJpL5GqbuNvS+4QjxuwtNGuZEEY0gOS4RIvWl/XfkxtWHMkzsKy08AO792xDGer4rL4Q1NcfI/H2V";

    // 256-bit AES key (literally the 32 us-ascii bytes of this string)
    String key = "sQsPQYesBM5qEM5OSxicFatIiLM459Bu";

    // Note: If your AES key is a string, and it's not clearly hex or base64, AND if the length of the string is the exact size of the AES key,
    // then *literally* use the ascii chars as the AES key.

    crypt.put_CryptAlgorithm("aes");
    crypt.put_CipherMode("ecb");
    crypt.put_KeyLength(256);
    // use the exact ascii bytes as the key.
    crypt.SetEncodedKey(key,"ascii");
    crypt.put_EncodingMode("base64");

    String pt = crypt.decryptStringENC(ct);

    Log.i(TAG, pt);

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}