更新 : 2007 年 11 月
名前空間 :
System.Security.Cryptography アセンブリ :
mscorlib (mscorlib.dll 内)
Public Function Decrypt ( _
rgb As Byte(), _
fOAEP As Boolean _
) As Byte()
Dim instance As RSACryptoServiceProvider
Dim rgb As Byte()
Dim fOAEP As Boolean
Dim returnValue As Byte()
returnValue = instance.Decrypt(rgb, fOAEP)
public byte[] Decrypt(
byte[] rgb,
bool fOAEP
)
public:
array<unsigned char>^ Decrypt(
array<unsigned char>^ rgb,
bool fOAEP
)
public byte[] Decrypt(
byte[] rgb,
boolean fOAEP
)
public function Decrypt(
rgb : byte[],
fOAEP : boolean
) : byte[]
パラメータ
- rgb
- 型 : array<System..::.Byte>[]()[]
復号化するデータ。
- fOAEP
- 型 : System..::.Boolean
Microsoft Windows XP 以降を実行するコンピュータだけで使用できる OAEP パディングを使用して、直接 RSA 復号化を実行する場合は true。それ以外の場合は、PKCS#1 v1.5 パディングを使用することを表す false。
このメソッドを使用して復号化できるデータを暗号化するには、Encrypt を使用します。
データの暗号化と復号化を行うコード例を次に示します。
この例では ASCIIEncoding クラスを使用しますが、大きなデータの操作では UnicodeEncoding クラスをお勧めします。暗号化された値は、nvarchar 型のデータとして Microsoft SQL Server 2005 に保存できます。
Imports System.Security.Cryptography
Imports System.Text
Module RSACSPExample
Sub Main()
Try
'Create a UnicodeEncoder to convert between byte array and string.
Dim ByteConverter As New ASCIIEncoding
Dim dataString As String = "Data to Encrypt"
'Create byte arrays to hold original, encrypted, and decrypted data.
Dim dataToEncrypt As Byte() = ByteConverter.GetBytes(dataString)
Dim encryptedData() As Byte
Dim decryptedData() As Byte
'Create a new instance of the RSACryptoServiceProvider class
' and automatically create a new key-pair.
Dim RSAalg As New RSACryptoServiceProvider
'Display the origianl data to the console.
Console.WriteLine("Original Data: {0}", dataString)
'Encrypt the byte array and specify no OAEP padding.
'OAEP padding is only available on Microsoft Windows XP or
'later.
encryptedData = RSAalg.Encrypt(dataToEncrypt, False)
'Display the encrypted data to the console.
Console.WriteLine("Encrypted Data: {0}", ByteConverter.GetString(encryptedData))
'Pass the data to ENCRYPT and boolean flag specifying
'no OAEP padding.
decryptedData = RSAalg.Decrypt(encryptedData, False)
'Display the decrypted plaintext to the console.
Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData))
Catch e As CryptographicException
'Catch this exception in case the encryption did
'not succeed.
Console.WriteLine(e.Message)
End Try
End Sub
End Module
using System;
using System.Security.Cryptography;
using System.Text;
class RSACSPSample
{
static void Main()
{
try
{
//Create a UnicodeEncoder to convert between byte array and string.
ASCIIEncoding ByteConverter = new ASCIIEncoding();
string dataString = "Data to Encrypt";
//Create byte arrays to hold original, encrypted, and decrypted data.
byte[] dataToEncrypt = ByteConverter.GetBytes(dataString);
byte[] encryptedData;
byte[] decryptedData;
//Create a new instance of the RSACryptoServiceProvider class
// and automatically create a new key-pair.
RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider();
//Display the origianl data to the console.
Console.WriteLine("Original Data: {0}", dataString);
//Encrypt the byte array and specify no OAEP padding.
//OAEP padding is only available on Microsoft Windows XP or
//later.
encryptedData = RSAalg.Encrypt(dataToEncrypt, false);
//Display the encrypted data to the console.
Console.WriteLine("Encrypted Data: {0}", ByteConverter.GetString(encryptedData));
//Pass the data to ENCRYPT and boolean flag specifying
//no OAEP padding.
decryptedData = RSAalg.Decrypt(encryptedData, false);
//Display the decrypted plaintext to the console.
Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData));
}
catch(CryptographicException e)
{
//Catch this exception in case the encryption did
//not succeed.
Console.WriteLine(e.Message);
}
}
}
using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Text;
int main()
{
try
{
//Create a UnicodeEncoder to convert between byte array and string.
ASCIIEncoding^ ByteConverter = gcnew ASCIIEncoding;
String^ dataString = "Data to Encrypt";
//Create byte arrays to hold original, encrypted, and decrypted data.
array<Byte>^dataToEncrypt = ByteConverter->GetBytes( dataString );
array<Byte>^encryptedData;
array<Byte>^decryptedData;
//Create a new instance of the RSACryptoServiceProvider class
// and automatically create a new key-pair.
RSACryptoServiceProvider^ RSAalg = gcnew RSACryptoServiceProvider;
//Display the origianl data to the console.
Console::WriteLine( "Original Data: {0}", dataString );
//Encrypt the byte array and specify no OAEP padding.
//OAEP padding is only available on Microsoft Windows XP or
//later.
encryptedData = RSAalg->Encrypt( dataToEncrypt, false );
//Display the encrypted data to the console.
Console::WriteLine( "Encrypted Data: {0}", ByteConverter->GetString( encryptedData ) );
//Pass the data to ENCRYPT and boolean flag specifying
//no OAEP padding.
decryptedData = RSAalg->Decrypt( encryptedData, false );
//Display the decrypted plaintext to the console.
Console::WriteLine( "Decrypted plaintext: {0}", ByteConverter->GetString( decryptedData ) );
}
catch ( CryptographicException^ e )
{
//Catch this exception in case the encryption did
//not succeed.
Console::WriteLine( e->Message );
}
}
import System.*;
import System.Security.Cryptography.*;
import System.Text.*;
class RSACSPSample
{
public static void main(String[] args)
{
try {
// Create a UnicodeEncoder to convert between byte array and string.
ASCIIEncoding byteConverter = new ASCIIEncoding();
String dataString = "Data to Encrypt";
// Create byte arrays to hold original, encrypted, and decrypted
// data.
ubyte dataToEncrypt[] = byteConverter.GetBytes(dataString);
ubyte encryptedData[];
ubyte decryptedData[];
// Create a new instance of the RSACryptoServiceProvider class
// and automatically create a new key-pair.
RSACryptoServiceProvider rsaAlg = new RSACryptoServiceProvider();
//Display the origianl data to the console.
Console.WriteLine("Original Data: {0}", dataString);
// Encrypt the byte array and specify no OAEP padding.
// OAEP padding is only available on Microsoft Windows XP or
// later.
encryptedData = rsaAlg.Encrypt(dataToEncrypt, false);
// Display the encrypted data to the console.
Console.WriteLine("Encrypted Data: {0}",
byteConverter.GetString(encryptedData));
// Pass the data to ENCRYPT and boolean flag specifying
// no OAEP padding.
decryptedData = rsaAlg.Decrypt(encryptedData, false);
// Display the decrypted plaintext to the console.
Console.WriteLine("Decrypted plaintext: {0}",
byteConverter.GetString(decryptedData));
}
catch (CryptographicException e) {
// Catch this exception in case the encryption did
// not succeed.
Console.WriteLine(e.get_Message());
}
} //main
} //RSACSPSample
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
.NET Framework
サポート対象 : 3.5、3.0、2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 3.5、2.0
参照
その他の技術情報