Can I use a PC/Mac keyboard as a Bluetooth keyboard for iPhone?
There are apps in App Store: iKeyboard ($9.99), Type2Phone ($9.99), 1Keyboard ($9.99) and Typeeto ($4.99) that allow to use your Mac's keyboard as Bluetooth keyboard. The obvious requirements are Mac with Bluetooth and recent OS X.
2017 Edit: As mentioned in other (newer) answers, there are iPhone apps available that can act as Bluetooth keyboards from the Mac. I've been using Typeeto myself. My original answer should be considered quite out of date now.
I'd recommend using the dedicated Bluetooth keyboard if it's not too much hassle, as it's currently the most elegant solution.
If you really want to type from the iMac though, you'll need a Jailbroken iPhone. There is a VNC server called "Veency" available from Cydia. You'll then need a VNC client for the iMac (I use JollysFastVNC myself). The iMac and iPhone also need to be networked via either Wifi or Bluetooth LAN.
You'll want to ignore the video and just look at the iPhone's screen while typing, because it lags heavily.
I would love to have something more elegant to suggest, but other mouse/keyboard-only solutions like Synergy or Teleport are Desktop/Notebook only at the moment.