I have done exactly this so it can be done. I just can't give you the code.
However, you are looking at it the wrong way. Forget about cookies - the Moodle cookies don't help you as they are only session identifiers. You will need to create a new authentication plugin for Moodle and use either a standard SSO method (e.g. OAuth) or roll your own using some basic web services. I did the latter using one-time tokens but it really depends on how secure you need it. That and I just don't understand OAuth