This article describes the AES encryption algorithm implemented by Java. Share to everyone for your reference, specific as follows:
Import Javax.crypto.Cipher;
Import Javax.crypto.spec.IvParameterSpec;
Import Javax.crypto.spec.SecretKeySpec;
Import android.util.Base64; /** * @author VIPIN.CB, vipin.cb@experionglobal.com <br> * Sep, 2013, 5:18:34 PM <br> * Package :-<b>com.veebow.util</b> <br> * project:-<b>Veebow</b> * <p> */Public CL
Ass Aescrypt {private final Cipher Cipher;
Private final Secretkeyspec key;
Private Algorithmparameterspec spec;
public static final String seed_16_character = "U1MJU1M0FDOUZ.QZ"; Public Aescrypt () throws Exception {//hash password with SHA-256 and crop the output to 128-bit for key messaged
Igest Digest = messagedigest.getinstance ("SHA-256");
Digest.update (Seed_16_character.getbytes ("UTF-8"));
byte[] keybytes = new BYTE[32];
System.arraycopy (Digest.digest (), 0, keybytes, 0, keybytes.length);
cipher = Cipher.getinstance ("aes/cbc/pkcs7padding"); Key = new Secretkeyspec (keYbytes, "AES");
Spec = Getiv ();
Public Algorithmparameterspec Getiv () {byte[] IV = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
Ivparameterspec Ivparameterspec;
Ivparameterspec = new Ivparameterspec (iv);
return ivparameterspec;
public string Encrypt (string plaintext) throws Exception {Cipher.init (Cipher.encrypt_mode, key, spec);
Byte[] encrypted = cipher.dofinal (Plaintext.getbytes ("UTF-8"));
String encryptedtext = new String (Base64.encode (encrypted, Base64.default), "UTF-8");
return encryptedtext;
public string Decrypt (string cryptedtext) throws Exception {Cipher.init (Cipher.decrypt_mode, key, spec);
byte[] bytes = Base64.decode (Cryptedtext, Base64.default);
byte[] decrypted = cipher.dofinal (bytes);
String decryptedtext = new String (decrypted, "UTF-8");
return decryptedtext;
}
}
PS: About encryption and decryption interested friends can also refer to the site online tools:
Password Security online detection:
Http://tools.jb51.net/password/my_password_safe
High Strength Password Generator:
Http://tools.jb51.net/password/CreateStrongPassword
MD5 Online Encryption Tool:
Http://tools.jb51.net/password/CreateMD5Password
Thunderbolt, Express, Cyclone URL encryption/decryption tool:
Http://tools.jb51.net/password/urlrethunder
Online hashing/hashing algorithm encryption tool:
Http://tools.jb51.net/password/hash_encrypt
I hope this article will help you with Java programming.