transistor to withstand 12v
For the buzzer to give optimal 'buzz', you need to switch the current on it from one direction to the other direction periodically. A buzzeer work a bit like a capacitor. If you just tie one side to 5V, and pulsate the other side, the buzzer won't give a loud sound because it will stay 'charged'.
So, for it to work properly, you need to put, for example, at pins 1 and 2, 5V and 0V, and then, 0V and 5V, and then, 5V and 0V, and so on.
This can be done with a microcontroler easily, however, some things to be carefull. If you switch the 5V/0V for 0V/5V directly, it will be like reversing a capacitor almost instentanously at the 2 pins of your micro. This will put a big load at the micro, and create potentially over-negative or over-positive voltage at the micro (like a brief -5V or +10V). The micro pins are usually protected agains't damage by this, but the problem is that it can create erratic behavior in the microcontroler (usually crash your program, sending the micro in lala-land).
So, on a micro, a correct approach is to send 5V/5V, then 5V/0V, then 0V/0V and finally, 0V/5V (each transition being at one quarter of the period, the period being 1 divided by the frequency).
This is a bit hard to use transistors, as the transistors will conduct current in only one direction. You could use a quad of 4 transistors, 2 per buzzer pin, arranged in totem-pole (push-pull). Don't tie the transistors base togetter though, as a transition from a 0 to 1 (or 1 to 0) will make both transistor conduct simultaneoulsy for a short period of time at each transistion, resulting in very high current flowing through the transistors. Then, this will require 4 micro pins, but beware of never putting both transistor of a pair in driving state at the same time unless you wish to also create a smoke generator. Transistors do run on smoke, and once the smoke get out of the transistor, it will stop working
Unless it's marijuana, the smoke won't give any 'buzz' to the buzzer