If it is digital, you can as long as the exposure isnt too long. think of the sensor as ur eye, you can glance quickly, but look too long and ur blind,
It won't hurt your eyes to point a Digital Camera at the sun overhead on a bright sunny day, but it can damage your camera's sensor by focusing the suns energy into a small dot. Remember playing with a magnifying glass as a kid? Same basic thing happens...except with the camera's sensor instead of ants
Overtime this could lead to problems with dead/stuck pixels, etc. And some older cameras have a problem where a large vertical streak appears in the image.
Nice sunsets are considered "okay" as long as the sun isn't directly visible. They generally won't cause problems, though I'd still recommend not looking at sunsets too long...it can mess with your vision. But they generally don't last a long time once the sun dips into the horizon, so it isn't too bad.
Generally if you want to take pictures of the sun you use a telescope with a special filter on the front element that removes harmful UV & IR light and also darkens the image a lot to make out details like sun spots, etc. Many camera filters can not get rid of any UV & IR light, which is why the ones for telescopes easily cost $200+ if they're worth anything.