RNGCryptoServiceProvider.GetNonZeroBytes 方法

定义

重载

GetNonZeroBytes(Byte[])

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

GetNonZeroBytes(Span<Byte>)

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

GetNonZeroBytes(Byte[])

Source:
RNGCryptoServiceProvider.cs
Source:
RNGCryptoServiceProvider.cs
Source:
RNGCryptoServiceProvider.cs

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

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);
RandomNumberGenerator^ rng = RandomNumberGenerator::Create();
rng->GetNonZeroBytes( random ); // The array is now filled with cryptographically strong random bytes, and none are zero.
byte[] random = new byte[100];

using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
{
    rng.GetNonZeroBytes(random); // The array is now filled with cryptographically strong random bytes, and none are zero.
}
Dim random() As Byte = New Byte(100) {}

Using rng As RandomNumberGenerator = RandomNumberGenerator.Create()
    rng.GetNonZeroBytes(random) ' bytes in random are now random and none are zero
End Using

注解

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

另请参阅

适用于

GetNonZeroBytes(Span<Byte>)

Source:
RNGCryptoServiceProvider.cs
Source:
RNGCryptoServiceProvider.cs
Source:
RNGCryptoServiceProvider.cs

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

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>

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

适用于