当前位置: 首页>>代码示例>>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;未经允许,请勿转载。