I have received the encryption request from a different provider, they were using AES GCM No Padding. When I am trying to decrypt it in ruby getting an error OpenSSL::Cipher::CipherError (). I observed in Java the IV is accepting the 16 bytes(Array of Zeros) whereas ruby is limited to 12 bytes only. I am missing something here. Appreciate your help in advance
Code Snippet for Java
SecretKey sessionKey = getSessionKey(); byte[] IV = new byte[16]; Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); SecretKeySpec keySpec = new SecretKeySpec(sessionKey.getEncoded(), "AES"); GCMParameterSpec gcmParameterSpec = new GCMParameterSpec(16 * 8, IV); cipher.init(Cipher.ENCRYPT_MODE, keySpec, gcmParameterSpec); byte[] encryptedText = cipher.doFinal(plaintext); responseMap.put("data", Base64.getEncoder().encodeToString(encryptedText)); Code snippet for Ruby
decrypted_key = "AES KEY" decode_data = Base64.strict_decode64(params["data"]) cipher_text_with_auth_tag = decode_data.unpack("C*") auth_tag = cipher_text_with_auth_tag.last(16).pack("C*") cipher_text = cipher_text_with_auth_tag[0..-17].pack("c*") decipher = OpenSSL::Cipher.new('AES-256-GCM') decipher. decrypt decipher.padding = 0 decipher.key = decrypted_key decipher.iv = "\x00" * 12 decipher.auth_data = '' decipher.auth_tag = auth_tag decrypted_data = decipher.update(cipher_text) + decipher.final