RNGCryptoServiceProvider.GetNonZeroBytes 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
以一個密碼學上強的非零值隨機序列填滿一個位元組區間。
多載
| 名稱 | Description |
|---|---|
| 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。
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>)
以一個密碼學上強的非零值隨機序列填滿一個位元組區間。
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))