Algorithme de Signature Numérique

aaa2017 Messages postés 9 Date d'inscription samedi 2 décembre 2017 Statut Membre Dernière intervention 29 mars 2024 - Modifié le 4 déc. 2017 à 17:17
 aaa2017 - 2 juin 2019 à 05:48
Bonjour,

L'application que je suis entraîne de réaliser en "Visual Studio 2010 Ultimate", ".Net FrameWork 4" me génère un problème au niveau de l'exécution qui est comme suite : "aucune réponse" et voilà la classe que j'ai créé dans le projet :
Imports System
Imports System.Security.Cryptography

 _

Class DSACSPSample


    Shared Sub Main()
        Try
            'Create a new instance of DSACryptoServiceProvider to generate
            'a new key pair.
            Using DSA As New DSACryptoServiceProvider

                'The hash value to sign.
                Dim HashValue 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 SignedHashValue As Byte() = DSASignHash(HashValue, DSA.ExportParameters(True), "SHA1")

                'Verify the hash and display the results.
                If DSAVerifyHash(HashValue, SignedHashValue, DSA.ExportParameters(False), "SHA1") Then
                    Console.WriteLine("The hash value was verified.")
                Else
                    Console.WriteLine("The hash value was not verified.")
                End If
            End Using

        Catch e As ArgumentNullException
            Console.WriteLine(e.Message)
        End Try
    End Sub


    Public Shared Function DSASignHash(ByVal HashToSign() As Byte, ByVal DSAKeyInfo As DSAParameters, ByVal HashAlg As String) As Byte()
        Try
            Dim DSAFormatter
            'Create a new instance of DSACryptoServiceProvider.
            Using DSA As New DSACryptoServiceProvider

                'Import the key information.   
                DSA.ImportParameters(DSAKeyInfo)

                'Create an DSASignatureFormatter object and pass it the 
                'DSACryptoServiceProvider to transfer the private key.
                DSAFormatter = New DSASignatureFormatter(DSA)
            End Using

            'Set the hash algorithm to the passed value.
            DSAFormatter.SetHashAlgorithm(HashAlg)

            'Create a signature for HashValue and return it.
            Return DSAFormatter.CreateSignature(HashToSign)
        Catch e As CryptographicException
            Console.WriteLine(e.Message)

            Return Nothing
        End Try
    End Function

    Public Shared Function DSAVerifyHash(ByVal HashValue() As Byte, ByVal SignedHashValue() As Byte, ByVal DSAKeyInfo As DSAParameters, ByVal HashAlg As String) As Boolean
        Try
            Dim DSADeformatter
            'Create a new instance of DSACryptoServiceProvider.
            Using DSA As New DSACryptoServiceProvider

                'Import the key information. 
                DSA.ImportParameters(DSAKeyInfo)

                'Create an DSASignatureDeformatter object and pass it the 
                'DSACryptoServiceProvider to transfer the private key.
                DSADeformatter = New DSASignatureDeformatter(DSA)
                'Set the hash algorithm to the passed value.
                DSADeformatter.SetHashAlgorithm(HashAlg)
            End Using

            'Verify signature and return the result. 
            Return DSADeformatter.VerifySignature(HashValue, SignedHashValue)
        Catch e As CryptographicException
            Console.WriteLine(e.Message)

            Return False
        End Try
    End Function
End Class


EDIT : Ajout des balises de code

Merci d'avance

1 réponse

Bonjour,

merci pour ces informations sur la signature numérique,

j'ai fais l'application de DSA (algorithme de signature numérique), qui se compose de 3 étapes :

1- La génération des clés : c réussi
2- La signature en utilisant le hachage SHA1 : c réussi
3- La vérification : c pas réussi

Le problème :
après le hachage d'un message, le destinataire veut récupérer le message original, comment faire ?
sachant que j ai programmé au Visual Studio 2010.
merci d avance
0
Rejoignez-nous