本文整理汇总了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();
}
示例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;
}
示例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;
}
示例4: generateRandom
public static byte[] generateRandom(int size)
{
SecureRandom random = new SecureRandom();
return random.GenerateSeed(32);
}