(int cipherMode, byte[] packetNumber, byte[] payload, byte[] associatedData)
| 68 | } |
| 69 | |
| 70 | public byte[] aesGCM(int cipherMode, byte[] packetNumber, byte[] payload, byte[] associatedData) throws Exception { |
| 71 | byte[] nonce = getNonce(packetNumber); |
| 72 | SecretKeySpec keySpec = new SecretKeySpec(this.key, "AES"); |
| 73 | Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); |
| 74 | GCMParameterSpec gcmParameterSpec = new GCMParameterSpec(128, nonce); |
| 75 | cipher.init(cipherMode, keySpec, gcmParameterSpec); |
| 76 | cipher.updateAAD(associatedData); |
| 77 | return cipher.doFinal(payload); |
| 78 | } |
| 79 | |
| 80 | public byte[] decryptPayload(byte[] packetNumber, byte[] encryptPayload, byte[] associatedData) throws Exception { |
| 81 | return aesGCM(Cipher.DECRYPT_MODE, packetNumber, encryptPayload, associatedData); |
no test coverage detected