java AES
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class AES {
public static byte[] encode(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
{
//paramArrayOfByte1 是key paramArrayOfByte2 是明文
if ((paramArrayOfByte1 == null) || (paramArrayOfByte1.length != 32))
return null;
try
{
SecretKeySpec localSecretKeySpec = new SecretKeySpec(paramArrayOfByte1, "AES");
Cipher localCipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
localCipher.init(1, localSecretKeySpec);
byte[] arrayOfByte = localCipher.doFinal(paramArrayOfByte2);
return arrayOfByte;
}
catch (Exception localException)
{
localException.printStackTrace();
}
return null;
}
public static String decode(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
{
if ((paramArrayOfByte1 == null) || (paramArrayOfByte1.length != 32))
return null;
try
{
SecretKeySpec localSecretKeySpec = new SecretKeySpec(paramArrayOfByte1, "AES");
Cipher localCipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
localCipher.init(2, localSecretKeySpec);
String str = new String(localCipher.doFinal(paramArrayOfByte2));
return str;
}
catch (Exception localException)
{
localException.printStackTrace();
}
return null;
}
}