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
- XmlText.cs
- VirtualPath.cs
- BufferBuilder.cs
- DbRetry.cs
- AutomationPropertyInfo.cs
- GeometryValueSerializer.cs
- FormatterConverter.cs
- ObjectDataSourceMethodEditor.cs
- RegexCode.cs
- MiniLockedBorderGlyph.cs
- SequenceFullException.cs
- ImageList.cs
- IndentedTextWriter.cs
- SelfIssuedSamlTokenFactory.cs
- PathFigure.cs
- TextRunCacheImp.cs
- ReadOnlyDictionary.cs
- ProcessStartInfo.cs
- FontSourceCollection.cs
- AttributeUsageAttribute.cs
- exports.cs
- RotateTransform3D.cs
- LicenseException.cs
- ValidationEventArgs.cs
- SoapTransportImporter.cs
- AddInControllerImpl.cs
- BindingExpressionUncommonField.cs
- XmlTextAttribute.cs
- RealProxy.cs
- ZipIOCentralDirectoryFileHeader.cs
- Int32RectConverter.cs
- LocationSectionRecord.cs
- WebPartZoneBase.cs
- GridViewRowCollection.cs
- Ops.cs
- HttpContext.cs
- File.cs
- OletxTransactionManager.cs
- ManagedIStream.cs
- XmlSchemaGroup.cs
- LocalizableAttribute.cs
- BuildProviderCollection.cs
- DashStyles.cs
- OutputChannelBinder.cs
- DbMetaDataColumnNames.cs
- Int32Collection.cs
- EncoderExceptionFallback.cs
- ParameterModifier.cs
- DecimalConverter.cs
- SqlProvider.cs
- InputProviderSite.cs
- StateInitializationDesigner.cs
- ServiceDocumentFormatter.cs
- BitmapDecoder.cs
- ObjectListSelectEventArgs.cs
- SectionInput.cs
- SafeHandles.cs
- BitmapSizeOptions.cs
- arclist.cs
- ZoneLinkButton.cs
- DataGridViewLinkColumn.cs
- BindingRestrictions.cs
- XamlValidatingReader.cs
- WMIGenerator.cs
- RecordBuilder.cs
- JapaneseCalendar.cs
- JoinSymbol.cs
- NativeMethods.cs
- ProgressBar.cs
- SessionStateSection.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- RowsCopiedEventArgs.cs
- PropertyMappingExceptionEventArgs.cs
- CompositionTarget.cs
- XmlSchemaAll.cs
- FontUnitConverter.cs
- ToolTipAutomationPeer.cs
- SeekStoryboard.cs
- CodeAccessSecurityEngine.cs
- COMException.cs
- ReachFixedDocumentSerializer.cs
- Logging.cs
- DynamicPropertyReader.cs
- TypeInfo.cs
- PageAsyncTask.cs
- ParentControlDesigner.cs
- StandardOleMarshalObject.cs
- DuplicateMessageDetector.cs
- SafeRightsManagementQueryHandle.cs
- WindowsTitleBar.cs
- ASCIIEncoding.cs
- ReceiveMessageAndVerifySecurityAsyncResultBase.cs
- DocumentSequenceHighlightLayer.cs
- IconBitmapDecoder.cs
- DataRow.cs
- RouteValueExpressionBuilder.cs
- FileVersionInfo.cs
- xmlformatgeneratorstatics.cs
- EntityContainerEmitter.cs
- StylusSystemGestureEventArgs.cs