Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can PKCS5Padding be in AES/GCM mode?

What's the padding mode for AES/GCM? I understood it can be NoPadding, as in ECB mode it can be PKCS5Padding, how about in GCM mode? in JCE interface, we need provide "algorithm/mode/padding" (Reference).

So I used the following code to get the instance and it works in JDK but failed in IBM SDK which says

cannot find provider for supporting AES/GCM/PKCS5Padding

 Cipher.getInstance("AES/GCM/PKCS5Padding");

What's real use case for padding?

like image 221
C.c Avatar asked Jul 06 '15 14:07

C.c


1 Answers

GCM is a streaming mode which means that the ciphertext is only as long as the plaintext (not including authentication tag). GCM doesn't require a padding. This means that the PKCS5Padding version is actually only a synonym for NoPadding for convenience during programming. Some providers don't have this strange mode.

The are cases where padding the plaintext makes sense. For example, you can hide the length of the actual plaintext by appending a random length PKCS5Padding.

like image 181
Artjom B. Avatar answered Oct 01 '22 14:10

Artjom B.