GenerateSeed() public method

public GenerateSeed ( int length ) : byte[]
length int
return byte[]
Exemplo n.º 1
0
        public static byte[] GetSeed(
            int length)
        {
            SecureRandom master = Master;

            master.SetSeed(DateTime.Now.Ticks);
            return(master.GenerateSeed(length));
        }
Exemplo n.º 2
0
        private static SecureString GenerateNewMachineKey(int keySize)
        {
            var random = new SecureRandom();
            random.SetSeed(random.GenerateSeed(128));

            var machineKeyString = "";
            for (var x = 0; x < keySize; x++)
            {
                machineKeyString += (char)random.Next(33, 126);
            }

            return machineKeyString.ConvertToSecureString();
        }
Exemplo n.º 3
0
        public bool verifyPassword(string Password)
        {
            this.Password = Password;

            byte[] password = Utility.StringToByteArray(this.Password);
            Gost3411Digest digest = new Gost3411Digest();
            SecureRandom random = new SecureRandom();
            byte[] salt = random.GenerateSeed(16);
            digest.BlockUpdate(password, 0, password.Length);
            digest.BlockUpdate(salt, 0, 16);
            byte[] hash = new byte[digest.GetDigestSize()];
            digest.DoFinal(hash, 0);

            return true;
        }
Exemplo n.º 4
0
        public LavaResult AddNewUser(LavaUser user)
        {
            LavaResult result = new LavaResult();

            SqlConnection conn = new SqlConnection(connectionString);

            SqlCommand cmdNewCustomer = new SqlCommand("Volcano.uspNewUser", conn);
            cmdNewCustomer.CommandType = CommandType.StoredProcedure;

            cmdNewCustomer.Parameters.Add(new SqlParameter("@UserName", SqlDbType.NChar, 32));
            cmdNewCustomer.Parameters["@UserName"].Value = user.UserName;

            byte[] password = Utility.StringToByteArray(user.Password);
            Gost3411Digest digest = new Gost3411Digest();
            SecureRandom random = new SecureRandom();
            byte[] salt = random.GenerateSeed(16);
            digest.BlockUpdate(password, 0, password.Length);
            digest.BlockUpdate(salt, 0, 16);
            byte[] hash = new byte[digest.GetDigestSize()];
            digest.DoFinal(hash, 0);

            cmdNewCustomer.Parameters.AddWithValue("@Password", hash);
            cmdNewCustomer.Parameters.AddWithValue("@Salt", salt);

            cmdNewCustomer.Parameters.Add(new SqlParameter("@UserID", SqlDbType.Int));
            cmdNewCustomer.Parameters["@UserID"].Direction = ParameterDirection.Output;

            try
            {
                conn.Open();
                cmdNewCustomer.ExecuteNonQuery();
                user.UserID = (int)cmdNewCustomer.Parameters["@UserID"].Value;
            }
            catch (SqlException sqlEx)
            {
                if (sqlEx.Errors.Count > 0) // Assume the interesting stuff is in the first error
                {
                    switch (sqlEx.Errors[0].Number)
                    {
                        case 2627: // Foreign Key violation
                            result.Result = LAVA_ERROR_CODE.USER_ALREADY_EXIST;
                            result.Message = "UserName already exist. " + sqlEx.Message;
                            break;
                        default:
                            result.Result = LAVA_ERROR_CODE.UNKNOWH_ERROR;
                            result.Message = "Customer ID was not returned. Account could not be created. " + sqlEx.Errors[0].Number + sqlEx.Message;
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                result.Result = LAVA_ERROR_CODE.UNKNOWH_ERROR;
                result.Message = "Customer ID was not returned. Account could not be created. " + ex.Message;
            }
            finally
            {
                conn.Close();
            }

            return result;
        }
Exemplo n.º 5
0
 public static byte[] generateRandom(int size)
 {
     SecureRandom random = new SecureRandom();
     return random.GenerateSeed(32);
 }