|
|
|
date: Mon, 25 Aug 2008 15:28:55 -0700 (PDT),
group: microsoft.public.dotnet.framework
back
Decryption
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
date: Mon, 25 Aug 2008 15:28:55 -0700 (PDT)
author: Jeff
Re: Decryption
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/GregoryBeamer#
or just read it:
http://feeds.feedburner.com/GregoryBeamer
********************************************
| Think outside the box! |
********************************************
"Jeff" 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
date: Mon, 25 Aug 2008 22:49:54 -0500
author: Cowboy \(Gregory A. Beamer\) oSpamM
Re: Decryption
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.cryptostream.aspx
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" 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
date: Tue, 26 Aug 2008 10:24:42 +0200
author: Patrice http://www.chez.com/scribe/
|
|