135 ByteBuffer b = ByteBuffer.allocate(4);
136 b.order(ByteOrder.BIG_ENDIAN);
137 int aadLengthInBits = aadBytes.length * 8;
138 b.putInt(aadLengthInBits);
139 byte[] result1 = b.array();
140 byte[] al =
new byte[8];
141 System.arraycopy(result1, 0, al, 4, 4);
143 byte[] concatenatedHmacInput =
new byte[aadBytes.length + ivBytes.length + cipherBytes.length + al.length];
144 System.arraycopy(aadBytes, 0, concatenatedHmacInput, 0, aadBytes.length);
145 System.arraycopy(ivBytes, 0, concatenatedHmacInput, aadBytes.length, ivBytes.length );
146 System.arraycopy(cipherBytes, 0, concatenatedHmacInput, aadBytes.length + ivBytes.length , cipherBytes.length);
147 System.arraycopy(al, 0, concatenatedHmacInput, aadBytes.length + ivBytes.length + cipherBytes.length, al.length);
150 Mac macImpl = Mac.getInstance(hmacShaAlg);
151 macImpl.init(hmacKeySpec);
152 macImpl.update(concatenatedHmacInput);
153 byte[] macEncoded = macImpl.doFinal();
156 return Arrays.copyOf(macEncoded, authTagLength);
abstract String getHmacShaAlgorithm()
abstract int getAuthenticationTagLength()