Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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. // // ==--== // // 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Span.cs
- BrowserDefinition.cs
- QilTargetType.cs
- DelegateSerializationHolder.cs
- EllipseGeometry.cs
- FlowDocumentFormatter.cs
- TypeValidationEventArgs.cs
- Membership.cs
- AvTraceFormat.cs
- CSharpCodeProvider.cs
- SafeNativeMethodsCLR.cs
- _UriSyntax.cs
- ValidatorCompatibilityHelper.cs
- QilValidationVisitor.cs
- IsolatedStoragePermission.cs
- BeginStoryboard.cs
- DataGridViewMethods.cs
- DependencyObjectProvider.cs
- DbConvert.cs
- Row.cs
- DefaultValueConverter.cs
- StackSpiller.Temps.cs
- InputMethod.cs
- SamlAttribute.cs
- Baml2006Reader.cs
- StringDictionary.cs
- XdrBuilder.cs
- Pair.cs
- Rights.cs
- Matrix.cs
- MediaPlayerState.cs
- TimelineCollection.cs
- Keywords.cs
- AQNBuilder.cs
- ThicknessAnimation.cs
- QilGeneratorEnv.cs
- EventsTab.cs
- ListViewInsertEventArgs.cs
- SimpleNameService.cs
- SystemFonts.cs
- BrushConverter.cs
- OrderedHashRepartitionEnumerator.cs
- Application.cs
- Expander.cs
- FontResourceCache.cs
- Point4D.cs
- ThreadStartException.cs
- UrlAuthFailedErrorFormatter.cs
- EventSetter.cs
- BamlRecordReader.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- OracleCommand.cs
- BamlBinaryReader.cs
- OverflowException.cs
- GestureRecognitionResult.cs
- DataViewListener.cs
- HtmlUtf8RawTextWriter.cs
- XmlSchemaSet.cs
- DependencyObjectType.cs
- HttpHostedTransportConfiguration.cs
- RegistryKey.cs
- HashHelper.cs
- DbConnectionInternal.cs
- UnauthorizedWebPart.cs
- NetworkStream.cs
- BuildProvider.cs
- UpdateRecord.cs
- Animatable.cs
- AxisAngleRotation3D.cs
- ConfigurationManagerInternal.cs
- ArrayConverter.cs
- ColorAnimationUsingKeyFrames.cs
- RequestTimeoutManager.cs
- Html32TextWriter.cs
- GeometryCombineModeValidation.cs
- WebConvert.cs
- CookieProtection.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- MultiPartWriter.cs
- PostBackOptions.cs
- ObjectItemConventionAssemblyLoader.cs
- XmlWrappingReader.cs
- SRGSCompiler.cs
- Point3DConverter.cs
- _ScatterGatherBuffers.cs
- UidManager.cs
- SplineKeyFrames.cs
- ButtonBase.cs
- UIElementHelper.cs
- TablePattern.cs
- SparseMemoryStream.cs
- ContentType.cs
- NavigationService.cs
- GradientSpreadMethodValidation.cs
- RangeValuePattern.cs
- XmlAttributeOverrides.cs
- TableParagraph.cs
- UnsafeNativeMethods.cs
- LinkLabel.cs
- TypeLoadException.cs