Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting equivalent of VB.NET decryption function in VFP
Message
De
17/03/2006 16:42:06
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Getting equivalent of VB.NET decryption function in VFP
Divers
Thread ID:
01105441
Message ID:
01105441
Vues:
109
I have the following VB.NET function that I need to convert in VFP to obtain the equivalent. Basically, it uses the System.Security.Cryptography class. One Web Service in .NET is encrypting some data but what we sent as the result is used later on in VFP. So, VFP should be able to accomplish this. Basically, this function should return the same result as the one in VFP as far as the decryption goes for the related string passed as parameter as well as the decryption key.
    ' The function used to decrypt the text
    Public Shared Function Decrypt(ByVal tcString As String, ByVal sDecrKey As String) As Boolean
        Dim llSuccess As Boolean
        Dim byKey() As Byte = {}
        Dim IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
        Dim inputByteArray(tcString.Length) As Byte
        llSuccess = False
        cDecrypt = ""
        Try
            byKey = System.Text.Encoding.UTF8.GetBytes(Mid(sDecrKey, 1, 8))
            Dim des As New DESCryptoServiceProvider
            inputByteArray = Convert.FromBase64String(tcString)
            Dim ms As New MemoryStream
            Dim cs As New CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write)
            cs.Write(inputByteArray, 0, inputByteArray.Length)
            cs.FlushFinalBlock()
            Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8
            cDecrypt = encoding.GetString(ms.ToArray())
            llSuccess = True
        Catch loError As Exception
            App.ErrorSetup(loError)
            If App.cError.StartsWith("Bad Data") Then
                App.cError = "You didn't encrypt the XML string with a valid key."
            End If
            If App.cError.StartsWith("Invalid character in a Base-64 string") Then
                App.cError = "Unable to decrypt that data."
            End If
        End Try
        Return llSuccess
    End Function
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform