Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random seed might be predictable #2

Open
giwiro opened this issue Jun 2, 2018 · 0 comments
Open

Random seed might be predictable #2

giwiro opened this issue Jun 2, 2018 · 0 comments

Comments

@giwiro
Copy link

giwiro commented Jun 2, 2018

In this function:

//creates random password for encryption
public string CreateRandomString(int length, String str)
{
            string valid = str;
            StringBuilder res = new StringBuilder();
            Random rnd = new Random();
            while (0 < length--) {
                res.Append(valid[rnd.Next(valid.Length)]);
            }
            return res.ToString();
}

Your are using System.Random() to generate random position index in the str string. The problem is that the default seed is generated by Environment.TickCount (https://referencesource.microsoft.com/#mscorlib/system/random.cs) and it can be predictable as it's said in this article: https://utkusen.com/blog/destroying-the-encryption-of-hidden-tear-ransomware.html.

Solution

Use RNGCryptoServiceProvider to generate the private key (https://dotnetcodr.com/2016/10/05/generate-truly-random-cryptographic-keys-using-a-random-number-generator-in-net/).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant