Gateway 1 – Java

import java.util.Base64;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;


import org.apache.commons.lang3.ArrayUtils;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

// For Java and JVM-based languages, you might need to install unrestricted policy file for JVM,
// which is provided by Sun. Please refer BouncyCastle FAQ if you get
// java.lang.SecurityException: Unsupported keysize or algorithm parameters or
// Illegal key size.

// If you cannot install unrestricted policy file for JVM because of some reason, you can try with reflection: See here.

public class Test {

	public static void main(String[] args) {

		try {
				Security.addProvider(new BouncyCastleProvider());

				// Data from configuration
				String keyFromConfiguration = "6fNDiYU0T0/evFpmfycNai/AqF24i+rT0OmuVw0/sGQ=";

				// Data from server
				String ivFromHttpHeader = "RYjpCMtUmK54T6Lk";
				String authTagFromHttpHeader = "FUajWHmZjP4A5qaa1G0kxw==";
				String httpBody = "9bIjURJIcwoKvQr+ifOTH3HbMX+IqmsRqHuG/I1GfbSX89JE5DcWh/p8QROC5pRAuYZ7"



				// Convert data to process		
				byte[] key = Base64.getDecoder().decode(keyFromConfiguration);
				byte[] iv = Base64.getDecoder().decode(ivFromHttpHeader);
				byte[] authTag = Base64.getDecoder().decode(authTagFromHttpHeader);
				byte[] encryptedText = Base64.getDecoder().decode(httpBody);

				// Unlike other programming language, We have to append auth tag at the end of
				// encrypted text in Java
				byte[] cipherText = ArrayUtils.addAll(encryptedText, authTag);

				// Prepare decryption
				SecretKeySpec keySpec = new SecretKeySpec(key, 0, 32, "AES");
				Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
				cipher.init(Cipher.DECRYPT_MODE, keySpec, new IvParameterSpec(iv));

				// Decrypt
				byte[] bytes = cipher.doFinal(cipherText);
				System.out.println(new String(bytes, Charsets.UTF_8));

		} catch (Exception e) {