Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / clr / src / BCL / System / Security / Cryptography / RNGCryptoServiceProvider.cs / 1 / RNGCryptoServiceProvider.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // // RNGCryptoServiceProvider.cs // namespace System.Security.Cryptography { using Microsoft.Win32; using System.Runtime.InteropServices; [System.Runtime.InteropServices.ComVisible(true)] public sealed class RNGCryptoServiceProvider : RandomNumberGenerator { #if !FEATURE_PAL SafeProvHandle m_safeProvHandle; #endif // // public constructors // #if !FEATURE_PAL public RNGCryptoServiceProvider() : this((CspParameters) null) {} #else public RNGCryptoServiceProvider() { } #endif #if !FEATURE_PAL public RNGCryptoServiceProvider(string str) : this((CspParameters) null) {} public RNGCryptoServiceProvider(byte[] rgb) : this((CspParameters) null) {} public RNGCryptoServiceProvider(CspParameters cspParams) { if (cspParams != null) m_safeProvHandle = Utils.AcquireProvHandle(cspParams); else m_safeProvHandle = Utils.StaticProvHandle; } #endif // // public methods // public override void GetBytes(byte[] data) { if (data == null) throw new ArgumentNullException("data"); #if !FEATURE_PAL Utils._GetBytes(m_safeProvHandle, data); #else if (!Win32Native.Random(true, data, data.Length)) throw new CryptographicException(Marshal.GetLastWin32Error()); #endif } public override void GetNonZeroBytes(byte[] data) { if (data == null) throw new ArgumentNullException("data"); #if !FEATURE_PAL Utils._GetNonZeroBytes(m_safeProvHandle, data); #else GetBytes(data); int indexOfFirst0Byte = data.Length; for (int i = 0; i < data.Length; i++) { if (data[i] == 0) { indexOfFirst0Byte = i; break; } } for (int i = indexOfFirst0Byte; i < data.Length; i++) { if (data[i] != 0) { data[indexOfFirst0Byte++] = data[i]; } } while (indexOfFirst0Byte < data.Length) { // this should be more than enough to fill the rest in one iteration byte[] tmp = new byte[2 * (data.Length - indexOfFirst0Byte)]; GetBytes(tmp); for (int i = 0; i < tmp.Length; i++) { if (tmp[i] != 0) { data[indexOfFirst0Byte++] = tmp[i]; if (indexOfFirst0Byte >= data.Length) break; } } } #endif } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SQLByte.cs
- DocumentPage.cs
- DelayedRegex.cs
- HatchBrush.cs
- UInt64Converter.cs
- XmlAnyElementAttributes.cs
- BinaryFormatter.cs
- TextPointerBase.cs
- Scanner.cs
- ParseHttpDate.cs
- PeerCustomResolverSettings.cs
- PieceNameHelper.cs
- DBConnectionString.cs
- SamlSubject.cs
- NativeMethods.cs
- Evidence.cs
- SqlServer2KCompatibilityCheck.cs
- SchemaObjectWriter.cs
- ReaderContextStackData.cs
- MissingFieldException.cs
- XmlNullResolver.cs
- AdditionalEntityFunctions.cs
- OneWayElement.cs
- UiaCoreApi.cs
- DefaultValueAttribute.cs
- Timer.cs
- DbDataAdapter.cs
- Stylus.cs
- NavigationFailedEventArgs.cs
- AutomationPeer.cs
- XmlWrappingReader.cs
- Border.cs
- ContextMenu.cs
- RewritingProcessor.cs
- DocumentAutomationPeer.cs
- SqlInternalConnectionTds.cs
- PluggableProtocol.cs
- NativeBuffer.cs
- ResourceDictionaryCollection.cs
- MenuItemCollection.cs
- StyleCollectionEditor.cs
- ReadOnlyDictionary.cs
- WebPartConnectionsConnectVerb.cs
- RootAction.cs
- PopupRootAutomationPeer.cs
- RolePrincipal.cs
- ObjectDisposedException.cs
- Rect.cs
- SettingsPropertyWrongTypeException.cs
- SqlDataSource.cs
- ConvertersCollection.cs
- ParsedAttributeCollection.cs
- BreakRecordTable.cs
- DataServiceEntityAttribute.cs
- MergeFilterQuery.cs
- RTLAwareMessageBox.cs
- HttpContext.cs
- OpenFileDialog.cs
- ListControlConvertEventArgs.cs
- DataGridRelationshipRow.cs
- BufferAllocator.cs
- XmlToDatasetMap.cs
- TextAutomationPeer.cs
- ProtectedConfiguration.cs
- OleDbInfoMessageEvent.cs
- Command.cs
- NetworkAddressChange.cs
- VirtualizedItemPattern.cs
- IItemContainerGenerator.cs
- DecimalKeyFrameCollection.cs
- Transform.cs
- KeyValuePairs.cs
- DelegatingTypeDescriptionProvider.cs
- EmptyCollection.cs
- DataGridDefaultColumnWidthTypeConverter.cs
- SchemaElementDecl.cs
- FormViewPageEventArgs.cs
- SqlFunctionAttribute.cs
- ConnectionManagementElementCollection.cs
- LogConverter.cs
- DataRelationCollection.cs
- AccessViolationException.cs
- IsolatedStorageFile.cs
- UIElement3D.cs
- SourceElementsCollection.cs
- ChannelFactory.cs
- SplitterPanel.cs
- SqlDataReaderSmi.cs
- SmiGettersStream.cs
- jithelpers.cs
- StreamReader.cs
- PolyBezierSegmentFigureLogic.cs
- TableCellsCollectionEditor.cs
- DataGridViewRowStateChangedEventArgs.cs
- XsdBuilder.cs
- OverrideMode.cs
- ImplicitInputBrush.cs
- EntityConnection.cs
- FontStretch.cs
- TemplatePartAttribute.cs