DSACryptoServiceProvider.VerifyData メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As DSACryptoServiceProvider Dim rgbData As Byte() Dim rgbSignature As Byte() Dim returnValue As Boolean returnValue = instance.VerifyData(rgbData, rgbSignature)
戻り値
検証の結果、署名が有効な場合は true。それ以外の場合は false。


DSACryptoServiceProvider クラスを使用してデータに署名してそのデータを検証するコード例を次に示します。
Imports System Imports System.Security.Cryptography _ Class DSACSPSample Shared Sub Main() Try 'Create a new instance of DSACryptoServiceProvider to generate 'a new key pair. Dim DSA As New DSACryptoServiceProvider() 'The data to sign. Dim Data As Byte() = {59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135} 'The value to hold the signed value. Dim SignedValue As Byte() = DSASignData(Data, DSA.ExportParameters(True)) 'Verify the data and display the results. If DSAVerifyData(Data, SignedValue, DSA.ExportParameters(False)) Then Console.WriteLine("The hash value was verified.") Else Console.WriteLine("The hash value was not verified.") End If Catch e As ArgumentNullException Console.WriteLine(e.Message) End Try End Sub Public Shared Function DSASignData(ByVal DataToSign() As Byte, ByVal DSAKeyInfo As DSAParameters) As Byte() Try 'Create a new instance of DSACryptoServiceProvider. Dim DSA As New DSACryptoServiceProvider() 'Import the key information. DSA.ImportParameters(DSAKeyInfo) 'Compute hash value, sign the hash, and return the signed hash. Return DSA.SignData(DataToSign) Catch e As CryptographicException Console.WriteLine(e.Message) Return Nothing End Try End Function Public Shared Function DSAVerifyData(ByVal Data() As Byte, ByVal SignedData() As Byte, ByVal DSAKeyInfo As DSAParameters) As Boolean Try 'Create a new instance of DSACryptoServiceProvider. Dim DSA As New DSACryptoServiceProvider() 'Import the key information. DSA.ImportParameters(DSAKeyInfo) 'Verify the signature and return the result. Return DSA.VerifyData(Data, SignedData) Catch e As CryptographicException Console.WriteLine(e.Message) Return False End Try End Function End Class
using System; using System.Security.Cryptography; class DSACSPSample { static void Main() { try { //Create a new instance of DSACryptoServiceProvider to generate //a new key pair. DSACryptoServiceProvider DSA = new DSACryptoServiceProvider(); //The data to sign. byte[] Data = {59,4,248,102,77,97,142,201,210,12,224,93,25,41,100,197 ,213,134,130,135}; //The value to hold the signed value. byte[] SignedValue = DSASignData(Data, DSA.ExportParameters(true)); //Verify the data and display the results. if(DSAVerifyData(Data, SignedValue, DSA.ExportParameters(false))) { Console.WriteLine("The hash value was verified."); } else { Console.WriteLine("The hash value was not verified."); } } catch(ArgumentNullException e) { Console.WriteLine(e.Message); } } public static byte[] DSASignData(byte[] DataToSign, DSAParameters DSAKeyInfo) { try { //Create a new instance of DSACryptoServiceProvider. DSACryptoServiceProvider DSA = new DSACryptoServiceProvider(); //Import the key information. DSA.ImportParameters(DSAKeyInfo); //Compute hash value, sign the hash, and return the signed hash. return DSA.SignData(DataToSign); } catch(CryptographicException e) { Console.WriteLine(e.Message); return null; } } public static bool DSAVerifyData(byte[] Data, byte[] SignedData, DSAParameters DSAKeyInfo) { try { //Create a new instance of DSACryptoServiceProvider. DSACryptoServiceProvider DSA = new DSACryptoServiceProvider(); //Import the key information. DSA.ImportParameters(DSAKeyInfo); //Verify the signature and return the result. return DSA.VerifyData(Data, SignedData); } catch(CryptographicException e) { Console.WriteLine(e.Message); return false; } } }
#using <System.dll> using namespace System; using namespace System::Security::Cryptography; array<Byte>^ DSASignData( array<Byte>^DataToSign, DSAParameters DSAKeyInfo ) { try { //Create a new instance of DSACryptoServiceProvider. DSACryptoServiceProvider^ DSA = gcnew DSACryptoServiceProvider; //Import the key information. DSA->ImportParameters( DSAKeyInfo ); //Compute hash value, sign the hash, and return the signed hash. return DSA->SignData( DataToSign ); } catch ( CryptographicException^ e ) { Console::WriteLine( e->Message ); return nullptr; } } bool DSAVerifyData( array<Byte>^Data, array<Byte>^SignedData, DSAParameters DSAKeyInfo ) { try { //Create a new instance of DSACryptoServiceProvider. DSACryptoServiceProvider^ DSA = gcnew DSACryptoServiceProvider; //Import the key information. DSA->ImportParameters( DSAKeyInfo ); //Verify the signature and return the result. return DSA->VerifyData( Data, SignedData ); } catch ( CryptographicException^ e ) { Console::WriteLine( e->Message ); return false; } } int main() { try { //Create a new instance of DSACryptoServiceProvider to generate //a new key pair. DSACryptoServiceProvider^ DSA = gcnew DSACryptoServiceProvider; //The data to sign. array<Byte>^Data = {59,4,248,102,77,97,142,201,210,12,224,93,25,41,100 ,197,213,134,130,135}; //The value to hold the signed value. array<Byte>^SignedValue = DSASignData( Data, DSA->ExportParameters( true ) ); //Verify the data and display the results. if ( DSAVerifyData( Data, SignedValue, DSA->ExportParameters( false ) ) ) { Console::WriteLine( "The hash value was verified." ); } else { Console::WriteLine( "The hash value was not verified." ); } } catch ( ArgumentNullException^ e ) { Console::WriteLine( e->Message ); } }
import System.* ; import System.Security.Cryptography.* ; class DSACSPSample { public static void main(String[] args) { try { // Create a new instance of DSACryptoServiceProvider to generate // a new key pair. DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(); //The data to sign. ubyte data[] = {59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135}; //The value to hold the signed value. ubyte signedValue[] = DSASignData(data, dsa.ExportParameters(true)); //Verify the data and display the results. if (DSAVerifyData(data, signedValue, dsa.ExportParameters(false))) { Console.WriteLine("The hash value was verified."); } else { Console.WriteLine("The hash value was not verified."); } } catch(ArgumentNullException e) { Console.WriteLine(e.get_Message()); } } //main public static ubyte[] DSASignData(ubyte dataToSign[], DSAParameters dsaKeyInfo) { try { // Create a new instance of DSACryptoServiceProvider. DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(); // Import the key information. dsa.ImportParameters(dsaKeyInfo); // Compute hash value, sign the hash, and return the signed hash. return dsa.SignData(dataToSign) ; } catch (CryptographicException e) { Console.WriteLine(e.get_Message()); return null ; } } //DSASignData public static boolean DSAVerifyData(ubyte data[], ubyte signedData[], DSAParameters dsaKeyInfo) { try { // Create a new instance of DSACryptoServiceProvider. DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(); // Import the key information. dsa.ImportParameters(dsaKeyInfo); // Verify the signature and return the result. return dsa.VerifyData(data, signedData) ; } catch (CryptographicException e) { Console.WriteLine(e.get_Message()); return false ; } } //DSAVerifyData } //DSACSPSample
DSACryptoServiceProvider を作成し、新しいキー ペアを生成してから、一部のデータに署名して、そのデータをテストするコード例を次に示します。
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 Sign" 'Create byte arrays to hold original, encrypted, and decrypted data. Dim dataToSign As Byte() = ByteConverter.GetBytes(dataString) Dim hashedData() As Byte Dim signedData() As Byte ' Create a SHA1CryptoServiceProvider object ' to hash the data that will be signed. Dim SHA1alg As New SHA1CryptoServiceProvider ' Hash the data to sign. hashedData = SHA1alg.ComputeHash(dataToSign) 'Create a new instance of the DSACryptoServiceProvider class ' and automatically create a new key-pair. Dim DSAalg As New DSACryptoServiceProvider 'Use the MapNameToOID method to get an object identifier '(OID) from the string name of the SHA1 algorithm. Dim OID As String = CryptoConfig.MapNameToOID("SHA1") ' Sign the hash and pass the OID. signedData = DSAalg.SignHash(hashedData, OID) ' Verify the signature and display the results to the ' console. If DSAalg.VerifySignature(hashedData, signedData) Then Console.WriteLine("The data was verified.") Else Console.WriteLine("The data does not match the signature.") End If 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 DSACSPSample { static void Main() { try { //Create a UnicodeEncoder to convert between byte array and string. ASCIIEncoding ByteConverter = new ASCIIEncoding(); string dataString = "Data to Sign"; //Create byte arrays to hold original, encrypted, and decrypted data. byte[] dataToSign = ByteConverter.GetBytes(dataString); byte[] hashedData; byte[] signedData; // Create a SHA1CryptoServiceProvider object // to hash the data that will be signed. SHA1CryptoServiceProvider SHA1alg = new SHA1CryptoServiceProvider(); // Hash the data to sign. hashedData = SHA1alg.ComputeHash(dataToSign); //Create a new instance of the DSACryptoServiceProvider class // and automatically create a new key-pair. DSACryptoServiceProvider DSAalg = new DSACryptoServiceProvider(); //Use the MapNameToOID method to get an object identifier //(OID) from the string name of the SHA1 algorithm. string OID = CryptoConfig.MapNameToOID("SHA1"); // Sign the hash and pass the OID. signedData = DSAalg.SignHash(hashedData, OID); // Verify the signature and display the results to the // console. if(DSAalg.VerifySignature(hashedData, signedData)) { Console.WriteLine("The data was verified."); } else { Console.WriteLine("The data does not match the signature."); } } 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 Sign"; //Create byte arrays to hold original, encrypted, and decrypted data. array<Byte>^dataToSign = ByteConverter->GetBytes( dataString ); array<Byte>^hashedData; array<Byte>^signedData; // Create a SHA1CryptoServiceProvider object // to hash the data that will be signed. SHA1CryptoServiceProvider^ SHA1alg = gcnew SHA1CryptoServiceProvider; // Hash the data to sign. hashedData = SHA1alg->ComputeHash( dataToSign ); //Create a new instance of the DSACryptoServiceProvider class // and automatically create a new key-pair. DSACryptoServiceProvider^ DSAalg = gcnew DSACryptoServiceProvider; //Use the MapNameToOID method to get an object identifier //(OID) from the string name of the SHA1 algorithm. String^ OID = CryptoConfig::MapNameToOID( "SHA1" ); // Sign the hash and pass the OID. signedData = DSAalg->SignHash( hashedData, OID ); // Verify the signature and display the results to the // console. if ( DSAalg->VerifySignature( hashedData, signedData ) ) { Console::WriteLine( "The data was verified." ); } else { Console::WriteLine( "The data does not match the signature." ); } } catch ( CryptographicException^ e ) { //Catch this exception in case the encryption did //not succeed. Console::WriteLine( e->Message ); } }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDSACryptoServiceProvider.VerifyData メソッドを検索する場合は、下記のリンクをクリックしてください。

- DSACryptoServiceProvider.VerifyData メソッドのページへのリンク