RNGCryptoServiceProvider.GetNonZeroBytes 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
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)。
data
為 null
。
範例
下列程式代碼範例會建立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))
參數
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應