RandomNumberGenerator.GetBytes 方法

定义

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

重载

GetBytes(Span<Byte>)

使用加密型强随机字节填充范围。

GetBytes(Byte[], Int32, Int32)

用加密型强随机值序列填充指定的字节数组。

GetBytes(Byte[])

当在派生类中重写时,用加密型强随机值序列填充字节数组。

GetBytes(Int32)

使用加密强随机值序列创建字节数组。

GetBytes(Span<Byte>)

Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs

使用加密型强随机字节填充范围。

public:
 virtual void GetBytes(Span<System::Byte> data);
public virtual void GetBytes (Span<byte> data);
abstract member GetBytes : Span<byte> -> unit
override this.GetBytes : Span<byte> -> unit
Public Overridable Sub GetBytes (data As Span(Of Byte))

参数

data
Span<Byte>

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

另请参阅

适用于

GetBytes(Byte[], Int32, Int32)

Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs

用加密型强随机值序列填充指定的字节数组。

public:
 virtual void GetBytes(cli::array <System::Byte> ^ data, int offset, int count);
public virtual void GetBytes (byte[] data, int offset, int count);
abstract member GetBytes : byte[] * int * int -> unit
override this.GetBytes : byte[] * int * int -> unit
Public Overridable Sub GetBytes (data As Byte(), offset As Integer, count As Integer)

参数

data
Byte[]

要用加密型强随机字节填充的数组。

offset
Int32

开始填充操作的数组的索引。

count
Int32

要填充的字节数。

例外

datanull

offsetcount 小于 0

offset 加上 count 超过 data 的长度。

适用于

GetBytes(Byte[])

Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs

当在派生类中重写时,用加密型强随机值序列填充字节数组。

public:
 abstract void GetBytes(cli::array <System::Byte> ^ data);
public abstract void GetBytes (byte[] data);
abstract member GetBytes : byte[] -> unit
Public MustOverride Sub GetBytes (data As Byte())

参数

data
Byte[]

要用加密型强随机字节填充的数组。

示例

以下示例创建一个长度为 100 字节的随机序列,并将其存储在 中 random

array<Byte>^ random = gcnew array<Byte>(100);

//RNGCryptoServiceProvider is an implementation of a random number generator.
RNGCryptoServiceProvider^ rng = gcnew RNGCryptoServiceProvider;
rng->GetBytes( random ); // The array is now filled with cryptographically strong random bytes.
byte[] random = new Byte[100];

//RNGCryptoServiceProvider is an implementation of a random number generator.
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetBytes(random); // The array is now filled with cryptographically strong random bytes.
Dim random() As Byte = New Byte(100) {}
       
'RNGCryptoServiceProvider is an implementation of an RNG
Dim rng As New RNGCryptoServiceProvider()
rng.GetBytes(random) ' bytes in random are now random

注解

字节数组的长度决定了生成的随机字节数。

另请参阅

适用于

GetBytes(Int32)

Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs

使用加密强随机值序列创建字节数组。

public:
 static cli::array <System::Byte> ^ GetBytes(int count);
public static byte[] GetBytes (int count);
static member GetBytes : int -> byte[]
Public Shared Function GetBytes (count As Integer) As Byte()

参数

count
Int32

要创建的随机值的字节数。

返回

Byte[]

使用加密强随机值填充的数组。

例外

count 小于零。

适用于