dsa

C# A random BigInt generator

非 Y 不嫁゛ 提交于 2019-11-27 23:36:41
问题 I'm about to implement the DSA algorithm, but there is a problem: choose "p", a prime number with L bits, where 512 <= L <= 1024 and L is a multiple of 64 How can I implement a random generator of that number? Int64 has "only" 63 bits length. 回答1: You can generate a random number with n bits using this code: var rng = new RNGCryptoServiceProvider(); byte[] bytes = new byte[n / 8]; rng.GetBytes(bytes); BigInteger p = new BigInteger(bytes); The result is, of course, random and not necessarily a