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
- StatusBarPanel.cs
- ConsumerConnectionPoint.cs
- XmlAttributeCollection.cs
- ColorInterpolationModeValidation.cs
- TextElementCollection.cs
- TextElementAutomationPeer.cs
- InternalPermissions.cs
- AliasedSlot.cs
- GotoExpression.cs
- EndpointNotFoundException.cs
- Rules.cs
- SuppressIldasmAttribute.cs
- TypedDataSourceCodeGenerator.cs
- QueryExtender.cs
- UnmanagedMemoryStream.cs
- PngBitmapEncoder.cs
- DerivedKeySecurityToken.cs
- ActivityDelegate.cs
- ServiceModelConfigurationSectionGroup.cs
- Emitter.cs
- HtmlWindowCollection.cs
- Utils.cs
- DataRowExtensions.cs
- Quaternion.cs
- DatagridviewDisplayedBandsData.cs
- AQNBuilder.cs
- PipelineModuleStepContainer.cs
- BitmapEffectCollection.cs
- WinEventHandler.cs
- DisplayMemberTemplateSelector.cs
- AsyncPostBackTrigger.cs
- XmlBoundElement.cs
- QilCloneVisitor.cs
- GridViewColumnHeader.cs
- Span.cs
- MetabaseServerConfig.cs
- SafeCloseHandleCritical.cs
- DataGridComponentEditor.cs
- CodeAssignStatement.cs
- DashStyle.cs
- SmiContext.cs
- ForEach.cs
- Formatter.cs
- MethodCallExpression.cs
- LinkArea.cs
- ProbeDuplexCD1AsyncResult.cs
- Point4DConverter.cs
- EdgeProfileValidation.cs
- xmlfixedPageInfo.cs
- TimeZone.cs
- ContentAlignmentEditor.cs
- RoleManagerModule.cs
- SimpleLine.cs
- DateTimeValueSerializer.cs
- ServiceBehaviorElement.cs
- StorageEndPropertyMapping.cs
- FontFamilyValueSerializer.cs
- IriParsingElement.cs
- StringAnimationBase.cs
- ConfigPathUtility.cs
- StylusPointPropertyId.cs
- QueryableDataSource.cs
- SectionInput.cs
- _UncName.cs
- Trace.cs
- DataGridViewElement.cs
- SchemaConstraints.cs
- PagedControl.cs
- DataGridViewSelectedColumnCollection.cs
- UserThread.cs
- TypeDescriptor.cs
- FirstMatchCodeGroup.cs
- ParentQuery.cs
- bindurihelper.cs
- Graph.cs
- PropertyRef.cs
- CodeArrayCreateExpression.cs
- MessagePartDescription.cs
- WebPartTransformerAttribute.cs
- ItemCollection.cs
- Single.cs
- DoubleIndependentAnimationStorage.cs
- XmlSchemas.cs
- Variable.cs
- WindowsFormsSynchronizationContext.cs
- DesignerActionListCollection.cs
- SingleSelectRootGridEntry.cs
- DataColumn.cs
- ContentPosition.cs
- CriticalExceptions.cs
- XmlDataImplementation.cs
- ToolStripItemClickedEventArgs.cs
- OpenFileDialog.cs
- ContentDesigner.cs
- AdRotator.cs
- UnorderedHashRepartitionStream.cs
- NestedContainer.cs
- XPathNode.cs
- CustomLineCap.cs
- TextBoxLine.cs