If you have enough threads available in the hole, then use the longer bolt if it won't bottom out...
General rule for minimum thread engagement is 1 1/2 times the bolt diameter. So a 1/2" diameter bolt should have a minimum of 3/4 inch of engaged threads. But for heavier loading, it's better to get the extra threads if you can.