That is not how encryption works. Every time you encrypt the same plaintext, you MUST get a different output. With GCM this is achieved by using a unique random IV each time – a nonce (number used once).
String airSecretKey = "Wk+Uzyyn8991w/2V5OIqiQ=="; // this key is now public so you cannot use it SecretKey key = new SecretKeySpec(Base64.getDecoder().decode(airSecretKey), "AES"); SecureRandom secureRandom = new SecureRandom(); byte iv = new byte; secureRandom.nextBytes(iv); AlgorithmParameters params = new GCMParameterSpec(128, iv); Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, key, params, secureRandom); cipher.updateAAD(...); // if used byte encrypted = cipher.doFinal(plaintext);
The Swift version should perform the same operations. Java generates the tag and appends it to the ciphertext. It looks like in Swift you have to handle it manually instead.
CLICK HERE to find out more related problems solutions.