Results 1 to 14 of 14

Thread: [RESOLVED] Help resolve this SIMPLE problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Resolved [RESOLVED] Help resolve this SIMPLE problem

    First off I am SO tired it's not even funny!

    I am trying to make sure my encrypt and decrypt functions are working
    properly.

    I was testing them out when I accidentally lost my work.

    I have put everything back together and I'm exhausted and I can't figure
    out where I am going wrong with this.

    Basically I'm taking a value from textbox1 and decrypting it and showing that
    value in textbox 2. Simple right?

    Here is the code for the decrypt button, how would I then call for the value
    in textbox 2?

    Code:
    Dim strArray As String() = Me.Decrypt(TextBox1.Text).Split(New Char() {"|"c})
            TextBox2 = ?
    Here is the decrypt function:

    Code:
     Public Function Decrypt(ByVal ciphertext As String) As String
            Dim str2 As String
            Dim str3 As String = DateTime.UtcNow.Hour.ToString.PadLeft(2, "0"c)
            Dim bytes As Byte() = Encoding.UTF8.GetBytes(("GpWhFbntD" & str3.ToString & "Qpop38D@dUnrF"))
            Dim rgbIV As Byte() = Encoding.UTF8.GetBytes("wFyEQPdN")
            Dim provider As New TripleDESCryptoServiceProvider With { _
                .BlockSize = &H40, _
                .Padding = PaddingMode.Zeros _
            }
            Using stream As MemoryStream = New MemoryStream
                Using stream2 As CryptoStream = New CryptoStream(stream, provider.CreateDecryptor(bytes, rgbIV), CryptoStreamMode.Write)
                    Dim buffer As Byte() = Convert.FromBase64String(ciphertext)
                    stream2.Write(buffer, 0, buffer.Length)
                    stream2.FlushFinalBlock()
                    str2 = Encoding.UTF8.GetString(stream.ToArray)
                End Using
            End Using
            Return str2
        End Function
    -Chris
    Last edited by cmmorris1; Aug 14th, 2011 at 08:48 PM.

  2. #2
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Help resolve this SIMPLE problem

    I'm a little confused, are you just creating a string "strArray" and putting the decrypted textbox1.text into it? then wouldn't you just simply say:

    Code:
     TextBox2.text = strArray
    This almost seems too simple to be your problem. Am I misunderstanding your question? But then again, I don't know what your Decrypt sub doesn, and I never used the Split command before, so I could be completely off, but I thought I would suggest something.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: Help resolve this SIMPLE problem

    Yeah, that's not going to work. I've already tried that.

    Thanks.

  4. #4
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Help resolve this SIMPLE problem

    Are you getting any errors? Type conversions? anything to go off of?

    I didn't just offer a (stupid lol) solution, but I also asked some questions to help clarify the situation. Its not that it 'doesn't work' its 'why doesn't it work'.

    Is the problem located in the dimention line? perhaps dimention on one line, and then set the variable on another? or, decrypt before you split? that way you can output the contents of strArray after each step and see where the problem is.

    I know that's not much of a 'solution' but without being in front of your code, that's all I can suggest.

    I really hope that helps.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: Help resolve this SIMPLE problem

    I've just updated my first post with the decrypt function.

    No errors. Just weird characters in the return of the decrypt string.

    I input an encrypted string and the decrypt will either return TRUE or FALSE

    -Chris

  6. #6
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Help resolve this SIMPLE problem

    one more question, lets say you encrypt the value "hello"

    you decrypt it and the value ends up being 'true' meaning the the enctyption was correct.

    what then do you want in textbox2? do you want the encrypted text, or "hello", or "true"?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: Help resolve this SIMPLE problem

    right now I am trying to decrypt an encrypted string in textbox1 and return the decrypted value into textbox2, so I want the return in textbox2 to show either TRUE or FALSE.

  8. #8
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Help resolve this SIMPLE problem

    Well, this really is beyond my knowledge set, but now this thread has a lot more information that will help someone with the know-how understand your problem better. Sorry I couldn't be of much help.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: Help resolve this SIMPLE problem

    No problem. Thanks stepdragon.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: Help resolve this SIMPLE problem

    Whew...I fixed it!

    Code:
    TextBox2.Text = strArray(0).ToString

  11. #11
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [RESOLVED] Help resolve this SIMPLE problem

    Your Decrypt() function returns a string. So, there is no need of storing it in a String array !

    So, it would look like this:
    vb.net Code:
    1. Dim strString As String = Me.Decrypt(TextBox1.Text).Split(New Char() {"|"c})
    2. TextBox2.Text = strString

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [RESOLVED] Help resolve this SIMPLE problem

    This is the error I get when I use your code:

    Value of type '1-dimensional array of String' cannot be converted to 'String'.

  13. #13
    New Member
    Join Date
    Aug 2011
    Posts
    7

    Re: [RESOLVED] Help resolve this SIMPLE problem

    this is similar to my question PLEES HEELP! =-C
    http://www.vbforums.com/showthread.php?p=4053148

  14. #14
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [RESOLVED] Help resolve this SIMPLE problem

    Quote Originally Posted by cmmorris1 View Post
    This is the error I get when I use your code:

    Value of type '1-dimensional array of String' cannot be converted to 'String'.
    Sorry, I didn't saw that you were passing splitted array of strings as parameter to the Decrypt() function.

    See if this works:
    vb.net Code:
    1. Imports System.Text
    2. Imports System.Security.Cryptography
    3. Imports System.IO
    4.  
    5. Public Class Form1
    6.  
    7.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    8.  
    9.         '~~~ empty the Textbox2
    10.         TextBox2.Text = ""
    11.  
    12.         '~~~ Split the contents in Textbox1 delimited by "|" into an array
    13.         Dim strArray() As String = TextBox1.Text.Split(New Char() {"|"c})   '~~~ holds the splitted contents
    14.  
    15.         '~~~ Loop through the array and decrypt it and store the decrypted string in the same array
    16.         For i As Integer = strArray.GetLowerBound(0) To strArray.GetUpperBound(0)
    17.             strArray(i) = Me.Decrypt(strArray(i))
    18.         Next
    19.  
    20.         '~~~ Join the array back to a string (opposite of "split"), delimited by a "||"
    21.         TextBox2.Text = String.Join("||", strArray)
    22.  
    23.     End Sub
    24.  
    25.     Public Function Decrypt(ByVal ciphertext As String) As String
    26.         Dim str2 As String
    27.         Dim str3 As String = DateTime.UtcNow.Hour.ToString.PadLeft(2, "0"c)
    28.         Dim bytes As Byte() = Encoding.UTF8.GetBytes(("GpWhFbntD" & str3.ToString & "Qpop38D@dUnrF"))
    29.         Dim rgbIV As Byte() = Encoding.UTF8.GetBytes("wFyEQPdN")
    30.         Dim provider As New TripleDESCryptoServiceProvider With { _
    31.             .BlockSize = &H40, _
    32.             .Padding = PaddingMode.Zeros _
    33.         }
    34.         Using stream As MemoryStream = New MemoryStream
    35.             Using stream2 As CryptoStream = New CryptoStream(stream, provider.CreateDecryptor(bytes, rgbIV), CryptoStreamMode.Write)
    36.                 Dim buffer As Byte() = Convert.FromBase64String(ciphertext)
    37.                 stream2.Write(buffer, 0, buffer.Length)
    38.                 stream2.FlushFinalBlock()
    39.                 str2 = Encoding.UTF8.GetString(stream.ToArray)
    40.             End Using
    41.         End Using
    42.         Return str2
    43.     End Function
    44. End Class

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width