RandomNumberGenerator.GetBytes Método

Definição

Preenche uma matriz de bytes com uma sequência de valores aleatória criptograficamente forte.

Sobrecargas

GetBytes(Span<Byte>)

Preenche um intervalo com bytes aleatórios criptograficamente fortes.

GetBytes(Byte[], Int32, Int32)

Preenche a matriz de bytes especificada com uma sequência de valores aleatória e criptograficamente forte.

GetBytes(Byte[])

Quando substituído em uma classe derivada, preenche uma matriz de bytes com uma sequência aleatória criptograficamente forte de valores.

GetBytes(Int32)

Cria uma matriz de bytes com uma sequência aleatória criptograficamente forte de valores.

GetBytes(Span<Byte>)

Origem:
RandomNumberGenerator.cs
Origem:
RandomNumberGenerator.cs
Origem:
RandomNumberGenerator.cs

Preenche um intervalo com bytes aleatórios criptograficamente fortes.

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))

Parâmetros

data
Span<Byte>

O intervalo a ser preenchido com bytes aleatórios criptograficamente fortes.

Confira também

Aplica-se a

GetBytes(Byte[], Int32, Int32)

Origem:
RandomNumberGenerator.cs
Origem:
RandomNumberGenerator.cs
Origem:
RandomNumberGenerator.cs

Preenche a matriz de bytes especificada com uma sequência de valores aleatória e criptograficamente forte.

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)

Parâmetros

data
Byte[]

A matriz a ser preenchida com bytes aleatórios criptograficamente fortes.

offset
Int32

O índice da matriz para iniciar a operação de preenchimento.

count
Int32

O número de bytes a preencher.

Exceções

data é null.

offset ou count é menor que 0

offset mais count excede o comprimento de data.

Aplica-se a

GetBytes(Byte[])

Origem:
RandomNumberGenerator.cs
Origem:
RandomNumberGenerator.cs
Origem:
RandomNumberGenerator.cs

Quando substituído em uma classe derivada, preenche uma matriz de bytes com uma sequência aleatória criptograficamente forte de valores.

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())

Parâmetros

data
Byte[]

A matriz a ser preenchida com bytes aleatórios criptograficamente fortes.

Exemplos

O exemplo a seguir cria uma sequência aleatória de 100 bytes de comprimento e a armazena em 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

Comentários

O comprimento da matriz de bytes determina quantos bytes aleatórios são produzidos.

Confira também

Aplica-se a

GetBytes(Int32)

Origem:
RandomNumberGenerator.cs
Origem:
RandomNumberGenerator.cs
Origem:
RandomNumberGenerator.cs

Cria uma matriz de bytes com uma sequência aleatória criptograficamente forte de valores.

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()

Parâmetros

count
Int32

O número de bytes de valores aleatórios a serem criados.

Retornos

Byte[]

Uma matriz preenchida com valores aleatórios criptograficamente fortes.

Exceções

count é menor que zero.

Aplica-se a