List of utility methods to do AES Encrypt
byte[] | aesEncrypt(byte[] source, Key key) aes Encrypt try { Cipher cipher = Cipher.getInstance(AES_ALGORITHM_NAME); cipher.init(Cipher.ENCRYPT_MODE, key); return cipher.doFinal(source); } catch (Exception e) { throw new IllegalStateException("AES ecnrypt error", e); |
String | aesEncrypt(String content, String encryptKey) aes Encrypt return parseByte2HexStr(aesEncryptToBytes(content, encryptKey));
|
String | aesEncrypt(String content, String key) aes Encrypt try { KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128, new SecureRandom(key.getBytes())); SecretKey secretKey = kgen.generateKey(); byte[] enCodeFormat = secretKey.getEncoded(); SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES"); Cipher cipher = Cipher.getInstance("AES"); byte[] byteContent = content.getBytes("utf-8"); ... |
byte[] | aesEncryptBytes(byte[] pBytes, SecretKeySpec pKeySpec, IvParameterSpec ivParameterSpec) aes Encrypt Bytes Cipher cipher = getAESCipher();
cipher.init(Cipher.ENCRYPT_MODE, pKeySpec, ivParameterSpec);
return cipher.doFinal(pBytes);
|
byte[] | aesEncryptToBytes(String content, String encryptKey) aes Encrypt To Bytes KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128, new SecureRandom(encryptKey.getBytes())); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES")); return cipher.doFinal(content.getBytes("utf-8")); |