The following code example uses the RSACryptoServiceProvider class to encrypt a string into an array of bytes and then decrypt the bytes back into a string.
Initializes a new instance of the RSACryptoServiceProvider class with a random key pair.
Initializes a new instance of the RSACryptoServiceProvider class with the specified parameters.
Initializes a new instance of the RSACryptoServiceProvider class with the specified key size and parameters.
Initializes a new instance of the RSACryptoServiceProvider class with a random key pair of the specified key size.
Represents the size, in bits, of the key modulus used by the asymmetric algorithm.
(Inherited from AsymmetricAlgorithm)Specifies the key sizes that are supported by the asymmetric algorithm.
(Inherited from AsymmetricAlgorithm)Gets a CspKeyContainerInfo object that describes additional information about a cryptographic key pair.
Gets the name of the key exchange algorithm available with this implementation of RSA.
Gets the name of the key exchange algorithm available with this implementation of RSA.
(Inherited from RSA)Gets the size of the current key.
Gets the key sizes that are supported by the asymmetric algorithm.
Gets the key sizes that are supported by the asymmetric algorithm.
(Inherited from AsymmetricAlgorithm)Gets or sets a value indicating whether the key should be persisted in the cryptographic service provider (CSP).
Gets a value that indicates whether the RSACryptoServiceProvider object contains only a public key.
Gets the name of the signature algorithm available with this implementation of RSA.
Gets the name of the signature algorithm available with this implementation of RSA.
(Inherited from RSA)Gets or sets a value indicating whether the key should be persisted in the computer's key store instead of the user profile store.
Releases all resources used by the AsymmetricAlgorithm class.
(Inherited from AsymmetricAlgorithm)Decrypts data with the RSA algorithm.
Decrypts data that was previously encrypted with the RSA algorithm by using the specified padding.
When overridden in a derived class, decrypts the input data using the specified padding mode.
(Inherited from RSA)Decrypts the input data using the specified padding mode.
(Inherited from RSA)Decrypts the input data using the specified padding mode.
(Inherited from RSA)Obsolete.
This method is not supported in the current version.
Obsolete.
When overridden in a derived class, decrypts the input data using the private key.
(Inherited from RSA)Releases all resources used by the current instance of the AsymmetricAlgorithm class.
(Inherited from AsymmetricAlgorithm)Releases the unmanaged resources used by the AsymmetricAlgorithm class and optionally releases the managed resources.
(Inherited from AsymmetricAlgorithm)Encrypts data with the RSA algorithm.
Encrypts data with the RSA algorithm using the specified padding.
When overridden in a derived class, encrypts the input data using the specified padding mode.
(Inherited from RSA)Encrypts the input data using the specified padding mode.
(Inherited from RSA)Encrypts the input data using the specified padding mode.
(Inherited from RSA)Obsolete.
This method is not supported in the current version.
Obsolete.
When overridden in a derived class, encrypts the input data using the public key.
(Inherited from RSA)Determines whether the specified object is equal to the current object.
(Inherited from Object)Exports a blob containing the key information associated with an RSACryptoServiceProvider object.
Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a byte-based password.
(Inherited from AsymmetricAlgorithm)Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password.
(Inherited from AsymmetricAlgorithm)Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a byte-based password, PEM encoded.
(Inherited from AsymmetricAlgorithm)Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password, PEM encoded.
(Inherited from AsymmetricAlgorithm)Exports the RSAParameters.
Exports the current key in the PKCS#8 PrivateKeyInfo format.
(Inherited from AsymmetricAlgorithm)Exports the current key in the PKCS#8 PrivateKeyInfo format, PEM encoded.
(Inherited from AsymmetricAlgorithm)Exports the current key in the PKCS#1 RSAPrivateKey format.
(Inherited from RSA)Exports the current key in the PKCS#1 RSAPrivateKey format, PEM encoded.
(Inherited from RSA)Exports the public-key portion of the current key in the PKCS#1 RSAPublicKey format.
(Inherited from RSA)Exports the public-key portion of the current key in the PKCS#1 RSAPublicKey format, PEM encoded.
(Inherited from RSA)Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format.
(Inherited from AsymmetricAlgorithm)Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format, PEM encoded.
(Inherited from AsymmetricAlgorithm)Releases the unmanaged resources held by this instance.
Initializes an RSA object from the key information from an XML string.
(Inherited from RSA)Serves as the default hash function.
(Inherited from Object)Gets the maximum number of bytes an RSA operation can produce.
(Inherited from RSA)Gets the Type of the current instance.
(Inherited from Object)When overridden in a derived class, computes the hash value of a specified portion of a byte array by using a specified hashing algorithm.
(Inherited from RSA)When overridden in a derived class, computes the hash value of a specified binary stream by using a specified hashing algorithm.
(Inherited from RSA)Imports a blob that represents RSA key information.
Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a byte-based password, replacing the keys for this object.
Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a byte-based password, replacing the keys for this object.
(Inherited from RSA)Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a char-based password, replacing the keys for this object.
Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a char-based password, replacing the keys for this object.
(Inherited from RSA)Imports an encrypted RFC 7468 PEM-encoded private key, replacing the keys for this object.
(Inherited from RSA)Imports an encrypted RFC 7468 PEM-encoded private key, replacing the keys for this object.
(Inherited from RSA)Imports an RFC 7468 PEM-encoded key, replacing the keys for this object.
(Inherited from RSA)Imports the specified RSAParameters.
Imports the public/private keypair from a PKCS#8 PrivateKeyInfo structure after decryption, replacing the keys for this object.
(Inherited from RSA)Imports the public/private keypair from a PKCS#1 RSAPrivateKey structure after decryption, replacing the keys for this object.
(Inherited from RSA)Imports the public key from a PKCS#1 RSAPublicKey structure after decryption, replacing the keys for this object.
(Inherited from RSA)Imports the public key from an X.509 SubjectPublicKeyInfo structure after decryption, replacing the keys for this object.
(Inherited from RSA)Creates a shallow copy of the current Object.
(Inherited from Object)Computes the hash value of the specified byte array using the specified hash algorithm and padding mode, and signs the resulting hash value.
(Inherited from RSA)Computes the hash value of a portion of the specified byte array using the specified hash algorithm and padding mode, and signs the resulting hash value.
(Inherited from RSA)Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
Computes the hash value of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
Computes the hash value of the specified data and signs it.
(Inherited from RSA)Computes the hash of the provided data with the specified algorithm and sign the hash with the current key, writing the signature into a provided buffer.
(Inherited from RSA)Computes the hash value of the specified stream using the specified hash algorithm and padding mode, and signs the resulting hash value.
(Inherited from RSA)Computes the hash value of the specified input stream using the specified hash algorithm, and signs the resulting hash value.
Computes the signature for the specified hash value using the specified padding.
When overridden in a derived class, computes the signature for the specified hash value using the specified padding.
(Inherited from RSA)Computes the signature for the specified hash value.
Computes the signature for the specified hash value using the specified padding.
(Inherited from RSA)Signs the hash with the current key, writing the signature into a provided buffer.
(Inherited from RSA)Returns a string that represents the current object.
(Inherited from Object)Creates and returns an XML string containing the key of the current RSA object.
(Inherited from RSA)Attempts to decrypt the input data using the specified padding mode, writing the result into a provided buffer.
(Inherited from RSA)Attempts to encrypt the input data with a specified padding mode into a provided buffer.
(Inherited from RSA)Attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a byte-based password.
(Inherited from RSA)Attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a char-based password.
(Inherited from RSA)Attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a byte-based password, PEM encoded.
(Inherited from AsymmetricAlgorithm)Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password, PEM encoded.
(Inherited from AsymmetricAlgorithm)Attempts to export the current key in the PKCS#8 PrivateKeyInfo format into a provided buffer.
(Inherited from RSA)Attempts to export the current key in the PEM-encoded PKCS#8 PrivateKeyInfo format into a provided buffer.
(Inherited from AsymmetricAlgorithm)Attempts to export the current key in the PKCS#1 RSAPrivateKey format into a provided buffer.
(Inherited from RSA)Attempts to export the current key in the PEM-encoded PKCS#1 RSAPrivateKey format into a provided buffer.
(Inherited from RSA)Attempts to export the current key in the PKCS#1 RSAPublicKey format into a provided buffer.
(Inherited from RSA)Attempts to export the current key in the PEM-encoded PKCS#1 RSAPublicKey format into a provided buffer.
(Inherited from RSA)Attempts to export the current key in the X.509 SubjectPublicKeyInfo format into a provided buffer.
(Inherited from RSA)Attempts to export the current key in the PEM-encoded X.509 SubjectPublicKeyInfo format into a provided buffer.
(Inherited from AsymmetricAlgorithm)Attempts to compute the hash of the provided data by using the specified algorithm, writing the results into a provided buffer.
(Inherited from RSA)Attempts to hash the provided data with the specified algorithm and sign the hash with the current key, writing the signature into a provided buffer.
(Inherited from RSA)Attempts to sign the hash with the current key, writing the signature into a provided buffer.
(Inherited from RSA)Verifies that a digital signature is valid by calculating the hash value of the specified data using the specified hash algorithm and padding, and comparing it to the provided signature.
(Inherited from RSA)Verifies that a digital signature is valid by calculating the hash value of the data in a portion of a byte array using the specified hash algorithm and padding, and comparing it to the provided signature.
(Inherited from RSA)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.
Verifies that a digital signature is valid by calculating the hash value of the specified data using the specified hash algorithm and padding, and comparing it to the provided signature.
(Inherited from RSA)Verifies that a digital signature is valid by calculating the hash value of the specified stream using the specified hash algorithm and padding, and comparing it to the provided signature.
(Inherited from RSA)Verifies that a digital signature is valid by determining the hash value in the signature using the specified hashing algorithm and padding, and comparing it to the provided hash value.
Verifies that a digital signature is valid by determining the hash value in the signature using the specified hash algorithm and padding, and comparing it to the provided hash value.
(Inherited from RSA)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.
Verifies that a digital signature is valid by determining the hash value in the signature using the specified hash algorithm and padding, and comparing it to the provided hash value.
(Inherited from RSA)This API supports the product infrastructure and is not intended to be used directly from your code.
For a description of this member, see Dispose().
(Inherited from AsymmetricAlgorithm)