VB.NET to C++ (Linux) code conversion

Discussion in 'Software' started by brianinoshkosh, Jun 29, 2011.

  1. brianinoshkosh

    brianinoshkosh Private E-2

    im having a small problem. i writing a program registration system for a vb.net app. it works great but i also need to generate the same codes on the web aswell. 2 of the functions im using are a bit confusing to me. could anyone help me out on porting these 2 functions into php or even a linux executable i could call from a php script.

    here are the two functions.

    Code:
    Private Function TripleDESEncode(ByVal value As String, ByVal key As String) As String
            Dim des As New Security.Cryptography.TripleDESCryptoServiceProvider
            des.IV = New Byte(7) {}
            Dim tiv() As Byte = New Byte(-1) {}
            Dim pdb As New Security.Cryptography.PasswordDeriveBytes(key, tiv)
            des.Key = pdb.CryptDeriveKey("RC2", "MD5", 128, New Byte(7) {})
            Dim ms As New IO.MemoryStream((value.Length * 2) - 1)
            Dim encStream As New Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(), Security.Cryptography.CryptoStreamMode.Write)
            Dim plainBytes As Byte() = Encoding.UTF8.GetBytes(value)
            encStream.Write(plainBytes, 0, plainBytes.Length)
            encStream.FlushFinalBlock()
            Dim encryptedBytes(CInt(ms.Length - 1)) As Byte
            ms.Position = 0
            ms.Read(encryptedBytes, 0, CInt(ms.Length))
            encStream.Close()
            des = Nothing
            pdb = Nothing
            ms = Nothing
            encStream = Nothing
            plainBytes = Nothing
            Return Convert.ToBase64String(encryptedBytes)
            encryptedBytes = Nothing
        End Function
    
        Private Function TripleDESDecode(ByVal value As String, ByVal key As String) As String
            Dim des As New Security.Cryptography.TripleDESCryptoServiceProvider
            des.IV = New Byte(7) {}
            Dim pdb As New Security.Cryptography.PasswordDeriveBytes(key, New Byte(-1) {})
            des.Key = pdb.CryptDeriveKey("RC2", "MD5", 128, New Byte(7) {})
            Dim encryptedBytes As Byte() = Convert.FromBase64String(value)
            Dim ms As New IO.MemoryStream(value.Length)
            Dim decStream As New Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(), Security.Cryptography.CryptoStreamMode.Write)
            decStream.Write(encryptedBytes, 0, encryptedBytes.Length)
            decStream.FlushFinalBlock()
            Dim plainBytes(CInt(ms.Length - 1)) As Byte
            ms.Position = 0
            ms.Read(plainBytes, 0, CInt(ms.Length))
            decStream.Close()
            des = Nothing
            pdb = Nothing
            ms = Nothing
            decStream = Nothing
            Return Encoding.UTF8.GetString(plainBytes)
            plainBytes = Nothing
        End Function
    
     
  2. PC-XT

    PC-XT Master Sergeant


MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds