public String decrypt(String ciphertext) { try { if(CommonUtils.isEmpty(ciphertext)) { return null; } byte[] saltDecrypt = spiSalt.getBytes(); SecretKeyFactory factoryKeyDecrypt = SecretKeyFactory.getInstance("xyz"); SecretKey tmp2 = factoryKeyDecrypt.generateSecret(new PBEKeySpec(spiKey.toCharArray(), saltDecrypt, iterations, keyLength)); SecretKeySpec decryptKey = new SecretKeySpec(tmp2.getEncoded(), "AES"); Cipher aesCipherDecrypt = Cipher.getInstance("AES/ECB/PKCS5Padding"); aesCipherDecrypt.init(Cipher.DECRYPT_MODE, decryptKey); byte[] e64bytes = StringUtils.getBytesUtf8(ciphertext); byte[] eBytes = Base64.decodeBase64(e64bytes); byte[] cipherDecode = aesCipherDecrypt.doFinal(eBytes); String decoded = StringUtils.newStringUtf8(cipherDecode); return decoded; }catch (Exception e){ e.printStackTrace(); return null; } }
java libraries
import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.SecretKeySpec;