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
- Merger.cs
- FlowDocumentReader.cs
- AsymmetricAlgorithm.cs
- SafeBuffer.cs
- ForceCopyBuildProvider.cs
- DbParameterCollectionHelper.cs
- TCEAdapterGenerator.cs
- ServicePoint.cs
- DependencyProperty.cs
- BinaryUtilClasses.cs
- AppDomainUnloadedException.cs
- RoleService.cs
- CrossSiteScriptingValidation.cs
- MatrixKeyFrameCollection.cs
- RadioButtonList.cs
- TimeoutValidationAttribute.cs
- TypeConstant.cs
- Utils.cs
- ColumnPropertiesGroup.cs
- StorageMappingItemCollection.cs
- SendActivityDesigner.cs
- StylusLogic.cs
- TextElement.cs
- InkPresenter.cs
- exports.cs
- XPathDocumentBuilder.cs
- WebPartDeleteVerb.cs
- ThrowHelper.cs
- SmtpNetworkElement.cs
- SpellCheck.cs
- HtmlFormParameterWriter.cs
- OLEDB_Util.cs
- ProgressBarBrushConverter.cs
- IDispatchConstantAttribute.cs
- TimeSpan.cs
- Font.cs
- WinEventTracker.cs
- NavigationPropertyEmitter.cs
- ComplexObject.cs
- PrintingPermissionAttribute.cs
- DbProviderFactoriesConfigurationHandler.cs
- DataGridItem.cs
- BaseParagraph.cs
- DocumentXPathNavigator.cs
- FieldBuilder.cs
- HttpListenerContext.cs
- ScriptResourceAttribute.cs
- AppDomainManager.cs
- RuntimeArgumentHandle.cs
- DashStyles.cs
- ComponentDispatcher.cs
- _ConnectionGroup.cs
- FormsIdentity.cs
- ObjectDataProvider.cs
- XPathAncestorQuery.cs
- FieldToken.cs
- SimpleBitVector32.cs
- CurrencyWrapper.cs
- PaintEvent.cs
- basecomparevalidator.cs
- SyndicationFeed.cs
- Ref.cs
- DataBinding.cs
- PictureBox.cs
- RealProxy.cs
- CachedTypeface.cs
- OracleFactory.cs
- PropertyValueUIItem.cs
- SQLDoubleStorage.cs
- SettingsSection.cs
- ColorConvertedBitmap.cs
- Image.cs
- ModuleBuilderData.cs
- EdmComplexTypeAttribute.cs
- FrameworkContentElement.cs
- ServiceDescriptionData.cs
- SqlCrossApplyToCrossJoin.cs
- InputLanguageSource.cs
- VirtualizingPanel.cs
- BlobPersonalizationState.cs
- DataViewManager.cs
- HMACSHA1.cs
- ContextStaticAttribute.cs
- DesignerExtenders.cs
- ComponentEditorPage.cs
- UInt32Storage.cs
- ObservableDictionary.cs
- dataprotectionpermissionattribute.cs
- HtmlInputHidden.cs
- ClientBuildManager.cs
- FlowDocumentPage.cs
- ColorTransformHelper.cs
- InstanceOwnerQueryResult.cs
- DataObject.cs
- ColorMap.cs
- ISAPIApplicationHost.cs
- KeyValuePair.cs
- ReceiveParametersContent.cs
- HttpHostedTransportConfiguration.cs
- SqlUserDefinedAggregateAttribute.cs