[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Jeff

8/25/2008 10:29:00 PM

Hi All,

I am trying to take a string that has been encrypted and decrypt it.
Here is the string: MMP61ubfQt4=


The following code runs, but the result is an empty string at the
end. Can anyone see what I am doing wrong?


Thanks,
Jeff


Public Shared Function decryptUser(ByVal userName As String) As
String
Dim inputInBytes() As Byte =
Convert.FromBase64String(userName)
Dim key() As Byte = Convert.FromBase64String("ABCDEFG/
LR3t49HgyCUXns9nfCpaAr0q")
Dim IV() As Byte = Convert.FromBase64String("ABCDEFGlS/U=")
Dim utf8encoder As UTF8Encoding = New UTF8Encoding
Dim tdesProvider As TripleDESCryptoServiceProvider = New
TripleDESCryptoServiceProvider


Dim cryptoTransform As ICryptoTransform =
tdesProvider.CreateDecryptor(key, IV)


Dim decryptedStream As MemoryStream = New MemoryStream
Dim cryptStream As CryptoStream = New
CryptoStream(decryptedStream, cryptoTransform,
CryptoStreamMode.Write)
cryptStream.Write(inputInBytes, 0, inputInBytes.Length)
cryptStream.FlushFinalBlock()
decryptedStream.Position = 0


Dim result(decryptedStream.Length - 1) As Byte
decryptedStream.Read(result, 0, decryptedStream.Length)
cryptStream.Close()
Dim myutf As UTF8Encoding = New UTF8Encoding
Return myutf.GetString(result)
End Function
2 Answers

Cowboy

8/26/2008 3:50:00 AM

0

Where is your encrypt routine. That will make a big difference whether the
decrypt is correct or not.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/Greg...

or just read it:
http://feeds.feedburner.com/Gre...

********************************************
| Think outside the box! |
********************************************
"Jeff" <jeff@washburnfamily.net> wrote in message
news:dd5c1222-c1eb-4c16-bae2-b4856e1c41b6@i76g2000hsf.googlegroups.com...
> Hi All,
>
> I am trying to take a string that has been encrypted and decrypt it.
> Here is the string: MMP61ubfQt4=
>
>
> The following code runs, but the result is an empty string at the
> end. Can anyone see what I am doing wrong?
>
>
> Thanks,
> Jeff
>
>
> Public Shared Function decryptUser(ByVal userName As String) As
> String
> Dim inputInBytes() As Byte =
> Convert.FromBase64String(userName)
> Dim key() As Byte = Convert.FromBase64String("ABCDEFG/
> LR3t49HgyCUXns9nfCpaAr0q")
> Dim IV() As Byte = Convert.FromBase64String("ABCDEFGlS/U=")
> Dim utf8encoder As UTF8Encoding = New UTF8Encoding
> Dim tdesProvider As TripleDESCryptoServiceProvider = New
> TripleDESCryptoServiceProvider
>
>
> Dim cryptoTransform As ICryptoTransform =
> tdesProvider.CreateDecryptor(key, IV)
>
>
> Dim decryptedStream As MemoryStream = New MemoryStream
> Dim cryptStream As CryptoStream = New
> CryptoStream(decryptedStream, cryptoTransform,
> CryptoStreamMode.Write)
> cryptStream.Write(inputInBytes, 0, inputInBytes.Length)
> cryptStream.FlushFinalBlock()
> decryptedStream.Position = 0
>
>
> Dim result(decryptedStream.Length - 1) As Byte
> decryptedStream.Read(result, 0, decryptedStream.Length)
> cryptStream.Close()
> Dim myutf As UTF8Encoding = New UTF8Encoding
> Return myutf.GetString(result)
> End Function

Patrice

8/26/2008 8:25:00 AM

0

Standard debugging applies i.e. have you put a breakpoint somewhere and
checked that strings are not empty, streams are written, arrays are not
empty etc... Here you should find that DecryptedStream.Length is 0 so the
CryptoStream part is wrong...

According to the doc
http://msdn.microsoft.com/en-us/library/system.security.cryptography.cryptos...
it lloks this is the other way round i.e. you provide an encypted stream to
the CryptoStream and reading the CryptoStream allows to read decrypted
data...

What if you try ?

--
Patrice

"Jeff" <jeff@washburnfamily.net> a écrit dans le message de groupe de
discussion :
dd5c1222-c1eb-4c16-bae2-b4856e1c41b6@i76g2000hsf.googlegroups.com...
> Hi All,
>
> I am trying to take a string that has been encrypted and decrypt it.
> Here is the string: MMP61ubfQt4=
>
>
> The following code runs, but the result is an empty string at the
> end. Can anyone see what I am doing wrong?
>
>
> Thanks,
> Jeff
>
>
> Public Shared Function decryptUser(ByVal userName As String) As
> String
> Dim inputInBytes() As Byte =
> Convert.FromBase64String(userName)
> Dim key() As Byte = Convert.FromBase64String("ABCDEFG/
> LR3t49HgyCUXns9nfCpaAr0q")
> Dim IV() As Byte = Convert.FromBase64String("ABCDEFGlS/U=")
> Dim utf8encoder As UTF8Encoding = New UTF8Encoding
> Dim tdesProvider As TripleDESCryptoServiceProvider = New
> TripleDESCryptoServiceProvider
>
>
> Dim cryptoTransform As ICryptoTransform =
> tdesProvider.CreateDecryptor(key, IV)
>
>
> Dim decryptedStream As MemoryStream = New MemoryStream
> Dim cryptStream As CryptoStream = New
> CryptoStream(decryptedStream, cryptoTransform,
> CryptoStreamMode.Write)
> cryptStream.Write(inputInBytes, 0, inputInBytes.Length)
> cryptStream.FlushFinalBlock()
> decryptedStream.Position = 0
>
>
> Dim result(decryptedStream.Length - 1) As Byte
> decryptedStream.Read(result, 0, decryptedStream.Length)
> cryptStream.Close()
> Dim myutf As UTF8Encoding = New UTF8Encoding
> Return myutf.GetString(result)
> End Function