private void Dispose(bool Disposing) { if (!_isDisposed && Disposing) { try { if (_rngGenerator != null) { _rngGenerator.Dispose(); _rngGenerator = null; } if (_seedGenerator != null) { _seedGenerator.Dispose(); _seedGenerator = null; } if (_byteBuffer != null) { Array.Clear(_byteBuffer, 0, _byteBuffer.Length); _byteBuffer = null; } } catch { } _isDisposed = true; } }
/// <summary> /// Reset the RNGCryptoServiceProvider instance. /// </summary> public void Reset() { if (_rngEngine != null) { _rngEngine.Dispose(); _rngEngine = null; } if (_seedGenerator != null) { _seedGenerator.Dispose(); _seedGenerator = null; } if (_rngGenerator != null) { _rngGenerator.Dispose(); _rngGenerator = null; } _rngEngine = GetCipher(_engineType); _seedGenerator = GetSeedGenerator(_seedType); _rngGenerator = new CTRDrbg(_rngEngine, true, _keySize); if (_seedGenerator != null) { _rngGenerator.Initialize(_seedGenerator.GetSeed(_rngEngine.BlockSize + _keySize)); } else { _rngGenerator.Initialize(_stateSeed); } _rngGenerator.Generate(_byteBuffer); _bufferIndex = 0; }