Results 1 to 3 of 3

Thread: [RESOLVED] Output decrypted text with CryptoStream

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2010
    Posts
    24

    Resolved [RESOLVED] Output decrypted text with CryptoStream

    Hi. Im using a sample code from msnd website - CryptoStream Class (http://msdn.microsoft.com/en-us/libr...ptostream.aspx)

    Using this code, i was expecting that

    Final would show me the decrypted text from the file
    Code:
    Dim Final As String = DecryptTextFromFile(FileName, RijndaelAlg.Key, RijndaelAlg.IV)
    However, when i try to do something to display Final, like MsgBox(Final) or Label1.text = Final , it outputs nothing.

    Where am i wrong?

  2. #2
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Output decrypted text with CryptoStream

    Hi,
    are you sure Compact Framework supports this?

    Take a look at http://msdn.microsoft.com/en-us/library/aa446559.aspx - there are notes on cryptographt part way down the page - I think you just have to use the crypto API
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2010
    Posts
    24

    Re: Output decrypted text with CryptoStream

    Quote Originally Posted by petevick View Post
    Hi,
    are you sure Compact Framework supports this?

    Take a look at http://msdn.microsoft.com/en-us/library/aa446559.aspx - there are notes on cryptographt part way down the page - I think you just have to use the crypto API
    Yes, it does. I found out that If i do the sample code from msdn like

    Code:
    ' Create a string to encrypt.
                Dim sData As String = "Here is some data to encrypt."
                Dim FileName As String = "CText.txt"
    
                ' Encrypt text to a file using the file name, key, and IV.
                EncryptTextToFile(sData, FileName, RijndaelAlg.Key, RijndaelAlg.IV)
    
                ' Decrypt the text from a file using the file name, key, and IV.
                Dim Final As String = DecryptTextFromFile(FileName, RijndaelAlg.Key, RijndaelAlg.IV)
    It works on my mobile.
    However, if i already have the CText.txt and just try to decrypt it like

    Code:
    ' Create a string to encrypt.
                Dim sData As String = "Here is some data to encrypt."
                Dim FileName As String = "CText.txt"
    
                ' Encrypt text to a file using the file name, key, and IV.
               ' EncryptTextToFile(sData, FileName, RijndaelAlg.Key, RijndaelAlg.IV)
    
                ' Decrypt the text from a file using the file name, key, and IV.
                Dim Final As String = DecryptTextFromFile(FileName, RijndaelAlg.Key, RijndaelAlg.IV)
    It does not work.

    I dont understand why drecrypt only does not work (even if it was previously encrypted with the same program, and only works if its first encrypted.

    Maybe because it generates a Key and IV each time the program runs? Maybe i need to store the Key and IV in the registry or in somewhere else so i can get it later?

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