Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Configuration / StrongNameUtility.cs / 1305376 / StrongNameUtility.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Configuration { using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using System.Security.Permissions; using Microsoft.Runtime.Hosting; internal class StrongNameUtility { // Help class shouldn't be instantiated. private StrongNameUtility() { } internal static bool GenerateStrongNameFile(string filename) { // variables that hold the unmanaged key IntPtr keyBlob = IntPtr.Zero; int generatedSize = 0; // create the key bool createdKey = StrongNameHelpers.StrongNameKeyGen(null, 0 /*No flags. 1 is to save the key in the key container */, out keyBlob, out generatedSize); // if there was a problem, translate it and report it if (!createdKey || keyBlob == IntPtr.Zero) { throw Marshal.GetExceptionForHR(StrongNameHelpers.StrongNameErrorInfo()); } try { Debug.Assert(keyBlob != IntPtr.Zero); // make sure the key size makes sense Debug.Assert(generatedSize > 0 && generatedSize <= Int32.MaxValue); if (generatedSize <= 0 || generatedSize > Int32.MaxValue) { throw new InvalidOperationException(SR.GetString(SR.Browser_InvalidStrongNameKey)); } // get the key into managed memory byte[] key = new byte[generatedSize]; Marshal.Copy(keyBlob, key, 0, (int)generatedSize); // write the key to the specified file using (FileStream snkStream = new FileStream(filename, FileMode.Create, FileAccess.Write)) { using (BinaryWriter snkWriter = new BinaryWriter(snkStream)) { snkWriter.Write(key); } } } finally { // release the unmanaged memory the key resides in if (keyBlob != IntPtr.Zero) { StrongNameHelpers.StrongNameFreeBuffer(keyBlob); } } return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Configuration { using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using System.Security.Permissions; using Microsoft.Runtime.Hosting; internal class StrongNameUtility { // Help class shouldn't be instantiated. private StrongNameUtility() { } internal static bool GenerateStrongNameFile(string filename) { // variables that hold the unmanaged key IntPtr keyBlob = IntPtr.Zero; int generatedSize = 0; // create the key bool createdKey = StrongNameHelpers.StrongNameKeyGen(null, 0 /*No flags. 1 is to save the key in the key container */, out keyBlob, out generatedSize); // if there was a problem, translate it and report it if (!createdKey || keyBlob == IntPtr.Zero) { throw Marshal.GetExceptionForHR(StrongNameHelpers.StrongNameErrorInfo()); } try { Debug.Assert(keyBlob != IntPtr.Zero); // make sure the key size makes sense Debug.Assert(generatedSize > 0 && generatedSize <= Int32.MaxValue); if (generatedSize <= 0 || generatedSize > Int32.MaxValue) { throw new InvalidOperationException(SR.GetString(SR.Browser_InvalidStrongNameKey)); } // get the key into managed memory byte[] key = new byte[generatedSize]; Marshal.Copy(keyBlob, key, 0, (int)generatedSize); // write the key to the specified file using (FileStream snkStream = new FileStream(filename, FileMode.Create, FileAccess.Write)) { using (BinaryWriter snkWriter = new BinaryWriter(snkStream)) { snkWriter.Write(key); } } } finally { // release the unmanaged memory the key resides in if (keyBlob != IntPtr.Zero) { StrongNameHelpers.StrongNameFreeBuffer(keyBlob); } } return true; } } } // 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
- XsdBuildProvider.cs
- LookupBindingPropertiesAttribute.cs
- ContentTextAutomationPeer.cs
- DbModificationClause.cs
- NameValueFileSectionHandler.cs
- HideDisabledControlAdapter.cs
- XmlResolver.cs
- DataTableReaderListener.cs
- propertytag.cs
- ChooseAction.cs
- WhileDesigner.cs
- PageTheme.cs
- RadioButton.cs
- DataServiceRequestOfT.cs
- TargetControlTypeCache.cs
- XmlTypeMapping.cs
- XmlReflectionMember.cs
- AnnotationObservableCollection.cs
- XmlCustomFormatter.cs
- IISMapPath.cs
- EntitySetRetriever.cs
- JapaneseCalendar.cs
- FirewallWrapper.cs
- ClientTarget.cs
- BevelBitmapEffect.cs
- HeaderCollection.cs
- Graph.cs
- XmlComplianceUtil.cs
- PropertyChangingEventArgs.cs
- StringInfo.cs
- SEHException.cs
- DataListItemCollection.cs
- GridItemProviderWrapper.cs
- SystemIPv6InterfaceProperties.cs
- MSAANativeProvider.cs
- WebSysDisplayNameAttribute.cs
- FixedBufferAttribute.cs
- SystemIPGlobalStatistics.cs
- WebPartEditVerb.cs
- DesignerAttribute.cs
- ThemeableAttribute.cs
- Directory.cs
- ScrollProviderWrapper.cs
- OneOfElement.cs
- Roles.cs
- SqlCacheDependencyDatabase.cs
- XmlSchemaObjectTable.cs
- WorkflowServiceHost.cs
- ThicknessConverter.cs
- UITypeEditor.cs
- EventProxy.cs
- EntityParameterCollection.cs
- FileAuthorizationModule.cs
- PeerNameRegistration.cs
- Cloud.cs
- WebServiceParameterData.cs
- Vector3DKeyFrameCollection.cs
- _ConnectStream.cs
- SmtpMail.cs
- InfoCardKeyedHashAlgorithm.cs
- ParallelTimeline.cs
- XmlNodeComparer.cs
- HtmlGenericControl.cs
- SqlProvider.cs
- TouchPoint.cs
- CharacterHit.cs
- clipboard.cs
- XmlSerializationGeneratedCode.cs
- RSAProtectedConfigurationProvider.cs
- QilInvokeLateBound.cs
- LayoutInformation.cs
- Animatable.cs
- XmlBindingWorker.cs
- DebugHandleTracker.cs
- IndexedString.cs
- SecurityState.cs
- StyleTypedPropertyAttribute.cs
- QuotedStringFormatReader.cs
- AddressingVersion.cs
- LinqDataSourceHelper.cs
- TypedDataSetSchemaImporterExtension.cs
- CryptoConfig.cs
- IChannel.cs
- FixedHighlight.cs
- TimeSpanConverter.cs
- MimePart.cs
- VBIdentifierNameEditor.cs
- DependentList.cs
- TransformedBitmap.cs
- WindowsBrush.cs
- Validator.cs
- WebSysDescriptionAttribute.cs
- PlaceHolder.cs
- DummyDataSource.cs
- HttpMethodAttribute.cs
- QEncodedStream.cs
- SecureStringHasher.cs
- DecimalConverter.cs
- SingleStorage.cs
- ClientType.cs