RSA.Encrypt Method

Definition

Overloads

Encrypt(Byte[], RSAEncryptionPadding)

When overridden in a derived class, encrypts the input data using the specified padding mode.

Encrypt(ReadOnlySpan<Byte>, RSAEncryptionPadding)

Encrypts the input data using the specified padding mode.

Encrypt(ReadOnlySpan<Byte>, Span<Byte>, RSAEncryptionPadding)

Encrypts the input data using the specified padding mode.

Encrypt(Byte[], RSAEncryptionPadding)

Source:
RSA.cs
Source:
RSA.cs
Source:
RSA.cs

When overridden in a derived class, encrypts the input data using the specified padding mode.

C#
public virtual byte[] Encrypt(byte[] data, System.Security.Cryptography.RSAEncryptionPadding padding);
C#
public abstract byte[] Encrypt(byte[] data, System.Security.Cryptography.RSAEncryptionPadding padding);

Parameters

data
Byte[]

The data to encrypt.

padding
RSAEncryptionPadding

The padding mode.

Returns

Byte[]

The encrypted data.

Exceptions

data or padding is null.

A derived class must override this method.

padding is unknown, or not supported by this implementation.

-or-

The length of data is too long for the combination of KeySize and the selected padding.

-or-

The encryption operation failed.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

Encrypt(ReadOnlySpan<Byte>, RSAEncryptionPadding)

Source:
RSA.cs
Source:
RSA.cs
Source:
RSA.cs

Encrypts the input data using the specified padding mode.

C#
public byte[] Encrypt(ReadOnlySpan<byte> data, System.Security.Cryptography.RSAEncryptionPadding padding);

Parameters

data
ReadOnlySpan<Byte>

The data to encrypt.

padding
RSAEncryptionPadding

The padding mode.

Returns

Byte[]

The encrypted data.

Exceptions

padding is null.

padding is unknown, or not supported by this implementation.

-or-

The length of data is too long for the combination of KeySize and the selected padding.

-or-

The encryption operation failed.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10

Encrypt(ReadOnlySpan<Byte>, Span<Byte>, RSAEncryptionPadding)

Source:
RSA.cs
Source:
RSA.cs
Source:
RSA.cs

Encrypts the input data using the specified padding mode.

C#
public int Encrypt(ReadOnlySpan<byte> data, Span<byte> destination, System.Security.Cryptography.RSAEncryptionPadding padding);

Parameters

data
ReadOnlySpan<Byte>

The data to encrypt.

destination
Span<Byte>

The buffer to receive the encrypted data.

padding
RSAEncryptionPadding

The padding mode.

Returns

The total number of bytes written to destination.

Exceptions

padding is null.

The buffer in destination is too small to hold the encrypted data.

padding is unknown, or not supported by this implementation.

-or-

The length of data is too long for the combination of KeySize and the selected padding.

-or-

The encryption operation failed.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10