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
備註
位元組陣列的長度會決定產生的密碼編譯強式隨機非零位元組數目。