Okay while I have no idea how sn.exe works - there is a very easy way to generate key. Use System.Diagnostics.Process to kick off a new instance of sn.exe and then read the results from disk. I see two apporaches, use sn.exe to generate a key then assign it to your assembly before/during compilation or write your assembly to disk then use SN.exe to sign it.

A third apporach would be to generate a key in advance and hold it as resource of your application, this has the advanatage that all dyncamical generated apps had the same key. If you want to ensure only apps that were dynamically generate were signed by that key you could encrypt the key itself, but then you have the problem of how to store the key that encrypts the key ...

None of these apporaches glamous as reverse engineering sn.exe but thier alot easier. If your really want to reverse engineer sn.exe then I'm pretty sure the crytographic algorthyms are covered as part of the EMCA strandard of C#.