Questions tagged [rngcryptoserviceprovider]

27 questions
14
votes
1 answer

RNGCryptoServiceProvider and Zeros?

walking through some cryptogtaphy stuff , I saw that RNGCryptoServiceProvider has 2 methods : link RNGCryptoServiceProvider.GetNonZeroBytes and RNGCryptoServiceProvider.GetBytes And so I ask : What is odd with Filling an array of bytes with…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
6
votes
4 answers

How can I use RNGCryptoServiceProvider to create a random password based on my preferred characters?

What I am currently doing to create a random password is like this: public static int getRandomNumber(int maxNumber) { if (maxNumber < 1) throw new System.Exception("The maxNumber value should be greater than 1"); …
Dexter
  • 6,170
  • 18
  • 74
  • 101
4
votes
1 answer

How can the RNGCryptoServiceProvider be used to generate Bridge hands?

The game of Bridge is played with 52 different playing cards that are randomly distributed among four players, each player ending up with thirteen cards: a so called "deal". Roughly a little less than 2^96 Bridge deals are possible. In this document…
Dabblernl
  • 15,831
  • 18
  • 96
  • 148
4
votes
2 answers

RNGCryptoServiceProvider with both min and max inclusive

I need a method, which returns random numbers from min to max, both numbers inclusive. I found some code in the article .NET Matters: Tales from the CryptoRandom from Stephen Toub and Shawn Farkas, where the method would look something like this: //…
sventevit
  • 4,766
  • 10
  • 57
  • 89
2
votes
1 answer

RNGCryptoServiceProvider.GetBytes() returns all zeros

I'm using the following code to generate an encryption salt. TripleDES tripleDES = TripleDES.Create() tripleDES.IV = new byte[8]; using (RNGCryptoServiceProvider rngProvider = new RNGCryptoServiceProvider()) { …
Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
2
votes
0 answers

How to authenticate user using Directory Services AccountManagement with password hash

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, Domain, UserName, Password) If i pass a correct password in code snippet above, authentication works fine but suppose i do not have the password but i have been provided with the …
1
vote
1 answer

RNGCryptoServiceProvider GetBytes() - how to restrict return values?

I have this method which returns a string of cryptographically strong random characters. First, GetBytes() populates a byte array with values from 0 to 255. Next, the return string is built by picking character number {byte value} % {length of…
Stian
  • 1,522
  • 2
  • 22
  • 52
1
vote
1 answer

How to use RNGCryptoServiceProvider generated string in url/query string

NOTE: I have already solved the problem mentioned in this post. After doing lot of google I couldn't find right solution. As now I know the answer. I thought this post will save other developer's time trying to solve same. Problem: I wanted to…
Balpreet Patil
  • 1,644
  • 2
  • 16
  • 16
1
vote
1 answer

C# RNGCryptoServiceProvider GetBytes(large byte array) vs looping GetBytes(1 byte)

I was wondering if there's a difference in security between the following: CASE A: byte[] data = new byte[47]; using(RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider()) { crypto.GetBytes(data); } CASE B: byte[] data = new…
BARJ
  • 1,543
  • 3
  • 20
  • 28
1
vote
1 answer

Random ThreadStatic Number within Ranges

How can I generate a random number from a range of numbers using a threadstatic seed? I need to create random numbers within a range from multiple methods. The problem is the same old duplicates. I found a MSDN blog that has a nice random generator,…
User970008
  • 1,135
  • 3
  • 20
  • 49
1
vote
2 answers

How to generate non-negative random numbers(integer) using RNGCryptoServiceProvider C#

I need to generate non-negative random integers in my code. The example below generates integers; using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider()) { // Buffer storage. byte[] data = new byte[4]; //…
pras007
  • 115
  • 11
1
vote
0 answers

Is there any way to get System.Security.Cryptography work on Windows Phone 8 to generate random numbers?

Is there any way to get the classes System.Security.Cryptography.RandomNumberGenerator or System.Security.Cryptography.RNGCryptoServiceProvider work on a Portable Class Library targeting Windows Phone 8 and Windows Store App? The main reason for…
1
vote
2 answers

Understanding this snippet of code _num = (_num & ~(1L << 63));

Can any explain what this section of code does: _num = (_num & ~(1L << 63)); I've have been reading up on RNGCryptoServiceProvider and came across http://codethinktank.blogspot.co.uk/2013/04/cryptographically-secure-pseudo-random.html with the code,…
George Phillipson
  • 830
  • 11
  • 39
1
vote
3 answers

How "good" is this method for generating random numbers?

I was searching on google for RNGCryptoServiceProvider with examples on how to limit the range between Max and Min, and still get an even distribution. Before I used modulo operator, but sometimes it I get strange values (above Max)... Anyways this…
Half_Baked
  • 340
  • 4
  • 18
1
vote
2 answers

In PHP what is the equivalent of C#'s RNGCryptoServiceProvider?

I'm studying basic security for asp.net and php, I was already able to implement the application on asp.net now what I want to do is come up with the same thing using php Here is the code that I'm using for my asp.net application that I want to…
Randel Ramirez
  • 3,671
  • 20
  • 49
  • 63
1
2