The current PKCS5Padding implementation in SunPKCS11 provider assumes that there is at least one padding byte available. However, this assumption isn't true when the user calles doFinal() without any data in decrypt mode. Certain classes, e.g. javax.crypto.CipherInput/OutputStream, use an empty doFinal() call as a way to discard the remaining data when its close() is called. For scenarios like this, the method should throw BadPaddingException instead of ArrayIndexOutOfBoundException.
|