How is MD5 Digest calculated in Asterisk (11.8.1)

I am trying to develop a program that will communicate via sip through an Asterisk server. The problem I am having is figuring out exactly what data to use to calculate the hash for the Authorization header.

Can anybody help me out with this or if I am in the wrong place direct me to where I can find out.

See the SIP RFC. Low level details are in the MD5 RFC.