Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / 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 } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- IImplicitResourceProvider.cs
- PropertyFilterAttribute.cs
- Panel.cs
- DropDownButton.cs
- ContextMenu.cs
- SmiMetaDataProperty.cs
- CookieParameter.cs
- AuthenticationServiceManager.cs
- SmtpNegotiateAuthenticationModule.cs
- RealProxy.cs
- WSUtilitySpecificationVersion.cs
- TreeView.cs
- ScriptMethodAttribute.cs
- SecurityContext.cs
- InternalsVisibleToAttribute.cs
- NativeMethods.cs
- WbmpConverter.cs
- TemplateBamlRecordReader.cs
- PointValueSerializer.cs
- ParameterCollection.cs
- Image.cs
- Collection.cs
- PolyBezierSegment.cs
- CorrelationManager.cs
- RemotingSurrogateSelector.cs
- BulletedList.cs
- OrderedEnumerableRowCollection.cs
- SystemUdpStatistics.cs
- ScriptControlManager.cs
- MdiWindowListItemConverter.cs
- ParamArrayAttribute.cs
- COMException.cs
- RenderOptions.cs
- MenuItemCollection.cs
- DeploymentSection.cs
- DataGridRowAutomationPeer.cs
- List.cs
- CultureInfo.cs
- NameTable.cs
- AdvancedBindingEditor.cs
- ColumnProvider.cs
- BinaryObjectWriter.cs
- DesignerContextDescriptor.cs
- CompositionDesigner.cs
- SoapConverter.cs
- XamlDesignerSerializationManager.cs
- ApplicationBuildProvider.cs
- ReliabilityContractAttribute.cs
- SettingsProperty.cs
- ObjectContext.cs
- PrinterUnitConvert.cs
- ClusterRegistryConfigurationProvider.cs
- DataSourceDescriptorCollection.cs
- CharAnimationBase.cs
- SelectionPattern.cs
- _LoggingObject.cs
- ProvidePropertyAttribute.cs
- WebControlParameterProxy.cs
- Pkcs9Attribute.cs
- TextAutomationPeer.cs
- SafeUserTokenHandle.cs
- RelationshipManager.cs
- PrimitiveSchema.cs
- ComplexTypeEmitter.cs
- SecurityTokenSerializer.cs
- ModelFunctionTypeElement.cs
- NativeMethods.cs
- KoreanLunisolarCalendar.cs
- _TimerThread.cs
- VisualBasicExpressionConverter.cs
- CollectionConverter.cs
- MenuBase.cs
- CodeArrayCreateExpression.cs
- TemplatingOptionsDialog.cs
- XmlValueConverter.cs
- MessageContractImporter.cs
- PassportAuthenticationEventArgs.cs
- ScrollContentPresenter.cs
- ComponentResourceManager.cs
- BinaryObjectWriter.cs
- AuthenticateEventArgs.cs
- ToolZone.cs
- AdRotator.cs
- LayoutEditorPart.cs
- ClientTarget.cs
- ChainedAsyncResult.cs
- WebPartConnectionCollection.cs
- MappingMetadataHelper.cs
- CodeTypeMemberCollection.cs
- DateTimeFormatInfo.cs
- GridPatternIdentifiers.cs
- DataFormats.cs
- StopStoryboard.cs
- BuildResult.cs
- UnsafeNetInfoNativeMethods.cs
- serverconfig.cs
- SafeRightsManagementQueryHandle.cs
- TypeElement.cs
- GridViewActionList.cs
- XmlSerializerVersionAttribute.cs