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>

要填入密碼編譯強式隨機非零位元組的範圍。

適用於