Why on earth would you want to do that?
"Rolling your own" with encryption is a good way to get problems later: it's a complicated field with complex code, and tiny differences can cause encrypted data to either be easily broken or corrupted beyond recovery.
But, if you must ... start here:
Reference Source[
^] - it's the source code that Microsoft use for RSA, and includes the code for key generation.
I'd still reccomend using the .NET Framework methods though.