troubleshooting Question

Encryption/decryption of file

Avatar of rwallacej
rwallacej asked on
.NET ProgrammingVisual Basic.NETASP.NET
8 Comments1 Solution582 ViewsLast Modified:
Hi

This question follows on from 21556745.

I used the example question 21556745 in a desktop form fine and it works. However if I use the DLL in a web application I get problems with

       A first chance exception of type 'System.FormatException' occurred

The aspx page loads an encrypted textfile then tries to decrypt it to a string.

Here's my code to load a file and then try to decrypt it to a string...

        If FileUpload1.HasFile Then
            Dim intFileLength As Integer, bytData() As Byte
            Dim objStream As System.IO.Stream

            intFileLength = FileUpload1.PostedFile.ContentLength
            ReDim bytData(intFileLength)
            objStream = FileUpload1.PostedFile.InputStream
            objStream.Read(bytData, 0, intFileLength)

            Dim fileContents As String = Encoding.ASCII.GetString(bytData)
            'this displays the file contents
            Me.TextBox_ReadFromFile.Text = fileContents    
       
            'attempt to decrypt the string            
            Dim decrypted As String = Crypto.Decrypt(fileContents, "theKeyHEre")

           'ERROR Happens here...
            Me.DecryptedFromFile.Text = fileContents
   End If

so....text loads fine but decrypt doesn't work.

However, if I have the following code in design mode
  fileContents = "a long string with exactly the same as is in the file being uploaded"
  decrypted = Crypto.Decrypt(fileContents, "theKeyHEre")
       
there is no error and the text decrypts fine.

Why would this be happening?  Text loaded from a file doesn't decrypted, the same text hard coded into class does - what's the solution? This is a strange one..

Thanks
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros