Compartir a través de


RSACryptoServiceProvider Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Performs asymmetric encryption and decryption using the implementation of the RSA algorithm provided by the cryptographic service provider (CSP). This class cannot be inherited.

Inheritance Hierarchy

System.Object
  System.Security.Cryptography.AsymmetricAlgorithm
    System.Security.Cryptography.RSA
      System.Security.Cryptography.RSACryptoServiceProvider

Namespace:  System.Security.Cryptography
Assembly:  mscorlib.Extensions (in mscorlib.Extensions.dll)

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public NotInheritable Class RSACryptoServiceProvider _
    Inherits RSA _
    Implements ICspAsymmetricAlgorithm
[ComVisibleAttribute(true)]
public sealed class RSACryptoServiceProvider : RSA, 
    ICspAsymmetricAlgorithm

The RSACryptoServiceProvider type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows Phone RSACryptoServiceProvider() Initializes a new instance of the RSACryptoServiceProvider class using the default key.
Public methodSupported by Silverlight for Windows Phone RSACryptoServiceProvider(CspParameters) Initializes a new instance of the RSACryptoServiceProvider class with the specified parameters.
Public methodSupported by Silverlight for Windows Phone RSACryptoServiceProvider(Int32) Initializes a new instance of the RSACryptoServiceProvider class with the specified key size.
Public methodSupported by Silverlight for Windows Phone RSACryptoServiceProvider(Int32, CspParameters) Initializes a new instance of the RSACryptoServiceProvider class with the specified key size and parameters.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows Phone CspKeyContainerInfo Gets a CspKeyContainerInfo object that describes additional information about a cryptographic key pair.
Public propertySupported by Silverlight for Windows Phone KeyExchangeAlgorithm Gets the name of the key exchange algorithm available with this implementation of RSA. (Overrides AsymmetricAlgorithm.KeyExchangeAlgorithm.)
Public propertySupported by Silverlight for Windows Phone KeySize Gets the size of the current key. (Overrides AsymmetricAlgorithm.KeySize.)
Public propertySupported by Silverlight for Windows Phone LegalKeySizes Gets the key sizes that are supported by the asymmetric algorithm. (Inherited from AsymmetricAlgorithm.)
Public propertySupported by Silverlight for Windows Phone PersistKeyInCsp Gets or sets a value indicating whether the key should be persisted in the cryptographic service provider (CSP).
Public propertySupported by Silverlight for Windows Phone PublicOnly Gets a value that indicates whether the RSACryptoServiceProvider object contains only a public key.
Public propertySupported by Silverlight for Windows Phone SignatureAlgorithm Gets the name of the signature algorithm available with this implementation of RSA. (Overrides AsymmetricAlgorithm.SignatureAlgorithm.)
Public propertyStatic memberSupported by Silverlight for Windows Phone UseMachineKeyStore Gets or sets a value indicating whether the key should be persisted in the computer's key store instead of the user profile store.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows Phone Clear Releases all resources used by the AsymmetricAlgorithm class. (Inherited from AsymmetricAlgorithm.)
Public methodSupported by Silverlight for Windows Phone Decrypt Decrypts data with the RSA algorithm.
Public methodSupported by Silverlight for Windows Phone DecryptValue This method is not supported in the current version. (Overrides RSA.DecryptValue(array<Byte[]).)
Public methodSupported by Silverlight for Windows Phone Dispose() Releases all resources used by the current instance of the AsymmetricAlgorithm class. (Inherited from AsymmetricAlgorithm.)
Protected methodSupported by Silverlight for Windows Phone Dispose(Boolean) Releases the unmanaged resources used by the AsymmetricAlgorithm class and optionally releases the managed resources. (Inherited from AsymmetricAlgorithm.)
Public methodSupported by Silverlight for Windows Phone Encrypt Encrypts data with the RSA algorithm.
Public methodSupported by Silverlight for Windows Phone EncryptValue This method is not supported in the current version. (Overrides RSA.EncryptValue(array<Byte[]).)
Public methodSupported by Silverlight for Windows Phone Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone ExportCspBlob Security Critical. Exports a blob containing the key information associated with an RSACryptoServiceProvider object.
Public methodSupported by Silverlight for Windows Phone ExportParameters Exports the RSAParameters. (Overrides RSA.ExportParameters(Boolean).)
Protected methodSupported by Silverlight for Windows Phone Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone FromXmlString Initializes an RSA object from the key information from an XML string. (Inherited from RSA.)
Public methodSupported by Silverlight for Windows Phone GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetType Gets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone ImportCspBlob Security Critical. Imports a blob that represents RSA key information.
Public methodSupported by Silverlight for Windows Phone ImportParameters Imports the specified RSAParameters. (Overrides RSA.ImportParameters(RSAParameters).)
Protected methodSupported by Silverlight for Windows Phone MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone SignData(array<Byte[], Object) Computes the hash value of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
Public methodSupported by Silverlight for Windows Phone SignData(Stream, Object) Computes the hash value of the specified input stream using the specified hash algorithm, and signs the resulting hash value.
Public methodSupported by Silverlight for Windows Phone SignData(array<Byte[], Int32, Int32, Object) Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
Public methodSupported by Silverlight for Windows Phone SignHash Computes the signature for the specified hash value by encrypting it with the private key.
Public methodSupported by Silverlight for Windows Phone ToString Returns a string that represents the current object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone ToXmlString Creates and returns an XML string containing the key of the current RSA object. (Inherited from RSA.)
Public methodSupported by Silverlight for Windows Phone VerifyData Verifies that a digital signature is valid by determining the hash value in the signature using the provided public key and comparing it to the hash value of the provided data.
Public methodSupported by Silverlight for Windows Phone VerifyHash Verifies that a digital signature is valid by determining the hash value in the signature using the provided public key and comparing it to the provided hash value.

Top

Fields

  Name Description
Protected fieldSupported by Silverlight for Windows Phone KeySizeValue Represents the size, in bits, of the key modulus used by the asymmetric algorithm. (Inherited from AsymmetricAlgorithm.)
Protected fieldSupported by Silverlight for Windows Phone LegalKeySizesValue Specifies the key sizes that are supported by the asymmetric algorithm. (Inherited from AsymmetricAlgorithm.)

Top

Remarks

This is the default implementation of RSA.

Silverlight for Windows Phone In Silverlight for Windows Phone, the RSACryptoServiceProvider supports key lengths from 384 bits to 4800 bits in increments of 8 bits.

Interoperation with the Microsoft Cryptographic API (CAPI)

Unlike the RSA implementation in unmanaged CAPI, the RSACryptoServiceProvider class reverses the order of an encrypted array of bytes after encryption and before decryption. By default, data encrypted by the RSACryptoServiceProvider class cannot be decrypted by the CAPI CryptDecrypt function and data encrypted by the CAPI CryptEncrypt method cannot be decrypted by the RSACryptoServiceProvider class.

If you do not compensate for the reverse ordering when interoperating between APIs, the RSACryptoServiceProvider class throws a CryptographicException.

To interoperate with CAPI, you must manually reverse the order of encrypted bytes before the encrypted data interoperates with another API. You can easily reverse the order of a managed byte array by calling the Array.Reverse method.

Version Information

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.