Code:
/ FX-1434 / FX-1434 / 1.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
- EntityConnectionStringBuilder.cs
- LayoutSettings.cs
- StubHelpers.cs
- ServicePointManagerElement.cs
- ManualWorkflowSchedulerService.cs
- KnowledgeBase.cs
- IPHostEntry.cs
- CounterCreationData.cs
- ContextStack.cs
- CdpEqualityComparer.cs
- PropertyPathConverter.cs
- CapabilitiesRule.cs
- PanelStyle.cs
- ProfilePropertyNameValidator.cs
- DBSqlParserColumn.cs
- PenThread.cs
- DependencySource.cs
- DataGridViewColumnDesignTimeVisibleAttribute.cs
- Pts.cs
- WebRequest.cs
- WorkflowElementDialogWindow.xaml.cs
- ProxyGenerator.cs
- Repeater.cs
- WithStatement.cs
- EntityContainer.cs
- ComponentGuaranteesAttribute.cs
- ScrollEvent.cs
- EntityModelSchemaGenerator.cs
- FontWeightConverter.cs
- MatrixAnimationUsingPath.cs
- WebScriptEndpoint.cs
- IOThreadTimer.cs
- FilteredDataSetHelper.cs
- _AutoWebProxyScriptEngine.cs
- odbcmetadatacolumnnames.cs
- ExclusiveHandle.cs
- Rect3DConverter.cs
- MultiAsyncResult.cs
- Point3D.cs
- ProfileManager.cs
- CurrentChangedEventManager.cs
- BypassElement.cs
- RegexWorker.cs
- HostTimeoutsElement.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- XsltSettings.cs
- IntegerCollectionEditor.cs
- HitTestParameters3D.cs
- ByteConverter.cs
- ClipboardProcessor.cs
- PhysicalOps.cs
- FormsAuthenticationUser.cs
- FixedDocumentSequencePaginator.cs
- CharUnicodeInfo.cs
- ObjectComplexPropertyMapping.cs
- PropertyItemInternal.cs
- BaseResourcesBuildProvider.cs
- _CookieModule.cs
- DataViewManager.cs
- DataSourceView.cs
- ParallelTimeline.cs
- DelegatingMessage.cs
- WebBaseEventKeyComparer.cs
- DesignerCatalogPartChrome.cs
- PerformanceCounterCategory.cs
- SqlExpander.cs
- QuerySafeNavigator.cs
- OletxDependentTransaction.cs
- ScrollChangedEventArgs.cs
- PartialList.cs
- PathFigure.cs
- SelectedCellsCollection.cs
- ObjectSecurity.cs
- Duration.cs
- RecipientInfo.cs
- Setter.cs
- DataGridColumnHeader.cs
- ToolStripSplitButton.cs
- URLIdentityPermission.cs
- ListView.cs
- Function.cs
- DriveNotFoundException.cs
- AuthStoreRoleProvider.cs
- PropertyGridView.cs
- SortedSetDebugView.cs
- UDPClient.cs
- XmlSchemaElement.cs
- TagPrefixAttribute.cs
- Int64Storage.cs
- ProfileService.cs
- DataGridViewCellFormattingEventArgs.cs
- linebase.cs
- SmiRecordBuffer.cs
- ResizeGrip.cs
- PropertyPathConverter.cs
- LinqTreeNodeEvaluator.cs
- Point4D.cs
- XmlLoader.cs
- _AutoWebProxyScriptWrapper.cs
- ParallelRangeManager.cs