Jump to content

Number Gen (encrypted)


Giggo
 Share

Recommended Posts

i wrote a program in c with cryptography and it works very well but in AutoIt3 can't figure out how to use the algorithm in question

since system.random is not safe

System.Security.Cryptography.RNGCryptoServiceProvider

I use such code in c # and even if forced to generate 22 characters it is much safer than normal random

using System;
using System.Security.Cryptography;
 
namespace HauntedHouseSoftware.SecureNotePad.Tools
{
    public static class PasswordGenerator
    {
        public static string Generate(int passwordLength, bool singleCase)
        {
            if (passwordLength == 0)
            {
                throw new InvalidOperationException("passwordLength");
            }
 
            string password;
 
            using (var randomNumberGenerator = new RNGCryptoServiceProvider())
            {
                var randomNumber = new byte[64];
                randomNumberGenerator.GetBytes(randomNumber);
 
                password = Convert.ToBase64String(randomNumber);
            }
 
            password = password.Substring(0, passwordLength);
 
            if (singleCase)
            {
                password = password.ToLower();
            }
 
            return password;
        }
    }
}

me program c#

	private void Button1_Click(object sender, EventArgs e)
	{
		TextBox1.Text = GetRandomPassword();
	}

	private string GetRandomPassword()
	{
		StringBuilder stringBuilder = new StringBuilder();
		string text = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
		string text2 = text;
		int i = 0;
		for (int length = text2.Length; i < length; i = checked(i + 1))
		{
			char c = text2[i];
			if (char.IsLetterOrDigit(c))
			{
				stringBuilder.Append(c);
				if (stringBuilder.Length == 30)
				{
					break;
				}
			}
		}
		return stringBuilder.ToString();
	}

 

Edited by Giggo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...