當前位置: 首頁>>代碼示例>>C#>>正文


C# SecureRandom.GenerateSeed方法代碼示例

本文整理匯總了C#中Org.BouncyCastle.Security.SecureRandom.GenerateSeed方法的典型用法代碼示例。如果您正苦於以下問題:C# SecureRandom.GenerateSeed方法的具體用法?C# SecureRandom.GenerateSeed怎麽用?C# SecureRandom.GenerateSeed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Org.BouncyCastle.Security.SecureRandom的用法示例。


在下文中一共展示了SecureRandom.GenerateSeed方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GenerateNewMachineKey

        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();
        }
開發者ID:mRemoteNG,項目名稱:mRemoteNG,代碼行數:13,代碼來源:EncryptedSecureString.cs

示例2: verifyPassword

        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;
        }
開發者ID:Dekkee,項目名稱:LavaAxe,代碼行數:15,代碼來源:User.cs

示例3: AddNewUser

        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;
        }
開發者ID:Dekkee,項目名稱:LavaServer,代碼行數:62,代碼來源:SQLAdapter.cs

示例4: generateRandom

 public static byte[] generateRandom(int size)
 {
     SecureRandom random = new SecureRandom();
     return random.GenerateSeed(32);
 }
開發者ID:Dekkee,項目名稱:LavaAxe,代碼行數:5,代碼來源:Crypto.cs


注:本文中的Org.BouncyCastle.Security.SecureRandom.GenerateSeed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。