If the online installer doesn't accept your key, make sure you are entering the correct one. The online installer will ask you to enter your 26 digit license key -you can find your key on your Games & Subscriptions page. Delete the old CD installer from your computer and download the latest installer from the Blizzard downloads page.
You cannot install from CD anymore -your original 16 digits physical CD key will not work. However, if you registered your physical copy of Diablo II on your account, your original 16 digits CD key was converted to a new 26 digit digital license key. When you install Diablo II from a CD, the installer will ask you to enter the 16 digits CD key found inside the box.