Dear forum readers,
I am really, really new to Powershell. I started the whole thing very recently, when I realised that %random% used in .bat files was a very poor random generator. I won’t go through the whole thing, so said shortly, it seems to me that the best random number generators in Windows (Windows 8.1 at least) are the ones available through the CNG API. The BCryptGenRandom function is used for this, and requires a pointer to an algorithm specified via BCryptOpenAlgorithmProvider. I didn’t find any PowerShell/.NET counterpart of this, so I decided to do something which seems to be referred to as “P/Invoke” by knowing people.
Unfortunately, I don’t know how to convert the WINAPI types to types useable by PowerShell, and pinvoke.net didn’t help me, since they don’t document those BCrypt* functions… but fortunately I found this : http://www.exploit-monday.com/2012/12/list-all-win32native-functions.html which indicates a P/Invoke declaration is already made for BCryptOpenAlgorithmProvider. Accessing that declaration would help me much in designing a P/Invoke for BCryptGenRandom.
The problem is, all this looks terribly fuzzy for me right now, like a gas factory as we say in France to designate something overly complicated. Undoubtedly that’s because I’m still a noob, so I have two questions : how can I access those win32 function already P/Invoked, with its parameter and output types ? I suppose it must be something like [some.type.name]::FunctionName but I’ve been unable to find it with the information provided at the previously given URL.
An answer to the second question would be a bonus, but the question is more straightforward : what P/Invoke definition should I make to get access to BCryptGenRandom and BCryptOpenAlgorithmProvider ?
Thanks for your help !