RNGCryptoServiceProvider.GetNonZeroBytes 方法

定义

重载

GetNonZeroBytes(Byte[])

用经过加密的强随机非零值序列填充字节数组。

GetNonZeroBytes(Span<Byte>)

使用加密型强随机非零值序列填充字节范围。

GetNonZeroBytes(Byte[])

用经过加密的强随机非零值序列填充字节数组。

public:
 override void GetNonZeroBytes(cli::array <System::Byte> ^ data);
public override void GetNonZeroBytes (byte[] data);
override this.GetNonZeroBytes : byte[] -> unit
Public Overrides Sub GetNonZeroBytes (data As Byte())

参数

data
Byte[]

用经过加密的强随机非零值序列填充的数组。

例外

无法获取加密服务提供程序 (CSP)。

datanull

示例

下面的代码示例创建100非零字节的随机序列,并将其存储在中 random

array<Byte>^ random = gcnew array<Byte>(100);
//RNGCryptoServiceProvider is an implementation of a random number generator.
RNGCryptoServiceProvider^ rng = gcnew RNGCryptoServiceProvider;
rng->GetNonZeroBytes( random ); // The array is now filled with cryptographically strong random bytes, and none are zero.
byte[] random = new Byte[100];
//RNGCryptoServiceProvider is an implementation of a random number generator.
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetNonZeroBytes(random); // The array is now filled with cryptographically strong random bytes, and none are zero.
Dim random() As Byte = New Byte(100) {}
'RNGCryptoServiceProvider is an implementation of an RNG
Dim rng As New RNGCryptoServiceProvider()
rng.GetNonZeroBytes(random) ' bytes in random are now random and none are zero

注解

字节数组的长度决定了生成多少个经过加密的强随机非零字节。

另请参阅

适用于

GetNonZeroBytes(Span<Byte>)

使用加密型强随机非零值序列填充字节范围。

public:
 override void GetNonZeroBytes(Span<System::Byte> data);
public override void GetNonZeroBytes (Span<byte> data);
override this.GetNonZeroBytes : Span<byte> -> unit
Public Overrides Sub GetNonZeroBytes (data As Span(Of Byte))

参数

data
Span<Byte>

要用加密型强随机非零字节填充的范围。

适用于