本文整理汇总了C#中System.Security.Cryptography.RNGCryptoServiceProvider.GetNonZeroBytes方法的典型用法代码示例。如果您正苦于以下问题:C# System.Security.Cryptography.RNGCryptoServiceProvider.GetNonZeroBytes方法的具体用法?C# System.Security.Cryptography.RNGCryptoServiceProvider.GetNonZeroBytes怎么用?C# System.Security.Cryptography.RNGCryptoServiceProvider.GetNonZeroBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.RNGCryptoServiceProvider
的用法示例。
在下文中一共展示了System.Security.Cryptography.RNGCryptoServiceProvider.GetNonZeroBytes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ZActor
/// <summary>
/// You are using ZContext.Current!
/// </summary>
public ZActor(ZAction0 action, params object[] args)
: this(default(string), action, args)
{
var rnd0 = new byte[8];
using (var rng = new System.Security.Cryptography.RNGCryptoServiceProvider()) rng.GetNonZeroBytes(rnd0);
this.Endpoint = string.Format("inproc://{0}", ZContext.Encoding.GetString(rnd0));
}
示例2: GetRandomPrime
public async Task<IHttpActionResult> GetRandomPrime()
{
var rnd = new System.Security.Cryptography.RNGCryptoServiceProvider();
var bytes = new byte[16];
var result = await Task.Run(() =>
{
rnd.GetNonZeroBytes(bytes);
var res = new BigInteger(bytes);
while (!res.IsProbablePrime(10))
{
rnd.GetNonZeroBytes(bytes);
res = new BigInteger(bytes);
}
return res;
});
Debug.WriteLine(result);
return Json(result.ToString());
}
示例3: GetUniqueKey
public static string GetUniqueKey(int maxSize)
{
char[] chars = new char[62];
chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
byte[] data = new byte[1];
using (System.Security.Cryptography.RNGCryptoServiceProvider crypto = new System.Security.Cryptography.RNGCryptoServiceProvider())
{
crypto.GetNonZeroBytes(data);
data = new byte[maxSize];
crypto.GetNonZeroBytes(data);
}
StringBuilder result = new StringBuilder(maxSize);
foreach (byte b in data)
{
result.Append(chars[b % (chars.Length)]);
}
return result.ToString();
}
示例4: StartReporting
/// <summary>
/// Начинать слушать порт, на который приходят RTCP пакеты
/// и слать в ответ свои
/// </summary>
public void StartReporting()
{
var random = new System.Security.Cryptography.RNGCryptoServiceProvider();
byte[] randomBytes = new byte[sizeof(UInt32)];
random.GetNonZeroBytes(randomBytes);
recieverSSRC = BitConverter.ToUInt32(randomBytes, 0);
senderReportCount = 0;
receivedRtpPackets = 0;
recieverReportCount = 0;
initTimestamp = 0;
udpClient.StartReceiving();
}
示例5: GenerateSalt
/// <summary>
/// Gera um SALT.
/// </summary>
/// <returns>SALT.</returns>
private byte[] GenerateSalt()
{
System.Security.Cryptography.RNGCryptoServiceProvider v_randomnumbergenerator;
byte[] v_salt;
int v_saltlength;
if (this.v_minsaltlength == this.v_maxsaltlength)
v_saltlength = this.v_minsaltlength;
else
v_saltlength = this.GenerateRandomNumber(this.v_minsaltlength, this.v_maxsaltlength);
v_salt = new byte[v_saltlength];
v_randomnumbergenerator = new System.Security.Cryptography.RNGCryptoServiceProvider();
v_randomnumbergenerator.GetNonZeroBytes(v_salt);
v_salt[0] = (byte)((v_salt[0] & 0xfc) | (v_saltlength & 0x03));
v_salt[1] = (byte)((v_salt[1] & 0xf3) | (v_saltlength & 0x0c));
v_salt[2] = (byte)((v_salt[2] & 0xcf) | (v_saltlength & 0x30));
v_salt[3] = (byte)((v_salt[3] & 0x3f) | (v_saltlength & 0xc0));
return v_salt;
}