Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / clr / src / BCL / System / Security / Cryptography / RSAPKCS1SignatureFormatter.cs / 1 / RSAPKCS1SignatureFormatter.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // // RSAPKCS1SignatureFormatter.cs // namespace System.Security.Cryptography { [System.Runtime.InteropServices.ComVisible(true)] public class RSAPKCS1SignatureFormatter : AsymmetricSignatureFormatter { private RSA _rsaKey; private String _strOID; // // public constructors // public RSAPKCS1SignatureFormatter() {} public RSAPKCS1SignatureFormatter(AsymmetricAlgorithm key) { if (key == null) throw new ArgumentNullException("key"); _rsaKey = (RSA) key; } // // public methods // public override void SetKey(AsymmetricAlgorithm key) { if (key == null) throw new ArgumentNullException("key"); _rsaKey = (RSA) key; } public override void SetHashAlgorithm(String strName) { _strOID = CryptoConfig.MapNameToOID(strName); } public override byte[] CreateSignature(byte[] rgbHash) { if (_strOID == null) throw new CryptographicUnexpectedOperationException(Environment.GetResourceString("Cryptography_MissingOID")); if (_rsaKey == null) throw new CryptographicUnexpectedOperationException(Environment.GetResourceString("Cryptography_MissingKey")); if (rgbHash == null) throw new ArgumentNullException("rgbHash"); // Two cases here -- if we are talking to the CSP version or if we are talking to some other RSA provider. if (_rsaKey is RSACryptoServiceProvider) { return ((RSACryptoServiceProvider) _rsaKey).SignHash(rgbHash, _strOID); } else { byte[] pad = Utils.RsaPkcs1Padding(_rsaKey, CryptoConfig.EncodeOID(_strOID), rgbHash); // Create the signature by applying the private key to the padded buffer we just created. return _rsaKey.DecryptValue(pad); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // // RSAPKCS1SignatureFormatter.cs // namespace System.Security.Cryptography { [System.Runtime.InteropServices.ComVisible(true)] public class RSAPKCS1SignatureFormatter : AsymmetricSignatureFormatter { private RSA _rsaKey; private String _strOID; // // public constructors // public RSAPKCS1SignatureFormatter() {} public RSAPKCS1SignatureFormatter(AsymmetricAlgorithm key) { if (key == null) throw new ArgumentNullException("key"); _rsaKey = (RSA) key; } // // public methods // public override void SetKey(AsymmetricAlgorithm key) { if (key == null) throw new ArgumentNullException("key"); _rsaKey = (RSA) key; } public override void SetHashAlgorithm(String strName) { _strOID = CryptoConfig.MapNameToOID(strName); } public override byte[] CreateSignature(byte[] rgbHash) { if (_strOID == null) throw new CryptographicUnexpectedOperationException(Environment.GetResourceString("Cryptography_MissingOID")); if (_rsaKey == null) throw new CryptographicUnexpectedOperationException(Environment.GetResourceString("Cryptography_MissingKey")); if (rgbHash == null) throw new ArgumentNullException("rgbHash"); // Two cases here -- if we are talking to the CSP version or if we are talking to some other RSA provider. if (_rsaKey is RSACryptoServiceProvider) { return ((RSACryptoServiceProvider) _rsaKey).SignHash(rgbHash, _strOID); } else { byte[] pad = Utils.RsaPkcs1Padding(_rsaKey, CryptoConfig.EncodeOID(_strOID), rgbHash); // Create the signature by applying the private key to the padded buffer we just created. return _rsaKey.DecryptValue(pad); } } } } // 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
- SafeCryptoKeyHandle.cs
- ReadOnlyDataSourceView.cs
- ListViewInsertedEventArgs.cs
- ComplexBindingPropertiesAttribute.cs
- coordinatorscratchpad.cs
- DecoderReplacementFallback.cs
- UnauthorizedWebPart.cs
- EdmType.cs
- XmlUTF8TextReader.cs
- GridToolTip.cs
- SecurityAlgorithmSuite.cs
- SpanIndex.cs
- ToolStripItemEventArgs.cs
- DesignDataSource.cs
- ContextMenuStrip.cs
- FrameworkElementAutomationPeer.cs
- ThreadLocal.cs
- Geometry.cs
- EpmCustomContentSerializer.cs
- BinarySerializer.cs
- Ops.cs
- GradientStop.cs
- ZipIOCentralDirectoryFileHeader.cs
- EntityStoreSchemaFilterEntry.cs
- PackWebResponse.cs
- SharedPerformanceCounter.cs
- CommandField.cs
- SystemDiagnosticsSection.cs
- SqlDataAdapter.cs
- MultiPropertyDescriptorGridEntry.cs
- SelectionRangeConverter.cs
- HostingEnvironmentSection.cs
- TraceListener.cs
- CategoryAttribute.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- Token.cs
- SequenceDesigner.cs
- Repeater.cs
- XmlHelper.cs
- InstanceNormalEvent.cs
- BinaryFormatterWriter.cs
- CheckBox.cs
- SiteMap.cs
- xdrvalidator.cs
- EntityStoreSchemaGenerator.cs
- TranslateTransform.cs
- ClientProxyGenerator.cs
- FreeFormDesigner.cs
- SoapHeader.cs
- precedingquery.cs
- WebPartZone.cs
- QuaternionKeyFrameCollection.cs
- InfiniteTimeSpanConverter.cs
- TcpTransportManager.cs
- DirectoryRedirect.cs
- SelectionItemProviderWrapper.cs
- Logging.cs
- UDPClient.cs
- SafeHandles.cs
- TextSpan.cs
- Converter.cs
- InstanceCollisionException.cs
- PageCodeDomTreeGenerator.cs
- CultureInfoConverter.cs
- HashCodeCombiner.cs
- LookupNode.cs
- WindowsScrollBar.cs
- DynamicRenderer.cs
- ContractUtils.cs
- UserCancellationException.cs
- ValidatingPropertiesEventArgs.cs
- MediaContextNotificationWindow.cs
- StatusBarPanel.cs
- UnionCodeGroup.cs
- odbcmetadatafactory.cs
- ScriptHandlerFactory.cs
- HostedTransportConfigurationBase.cs
- TextDpi.cs
- SqlDataSourceCache.cs
- ConfigXmlAttribute.cs
- RuleSettings.cs
- cookieexception.cs
- SqlLiftIndependentRowExpressions.cs
- AutomationIdentifier.cs
- TableLayoutSettings.cs
- NullableFloatSumAggregationOperator.cs
- HttpCapabilitiesBase.cs
- __Error.cs
- Calendar.cs
- EventProxy.cs
- DbMetaDataFactory.cs
- AttributeCollection.cs
- BulletChrome.cs
- ValidatingReaderNodeData.cs
- CurrentChangingEventManager.cs
- GeometryValueSerializer.cs
- CacheOutputQuery.cs
- ValueTable.cs
- XmlSchemaSimpleContent.cs
- C14NUtil.cs