bug fixs for Issue 39&54; SHA2 certificate support

hi timkurvers,

I have do some bug fixs and also add SHA2 certificate support.
Please review my code.