Decryption

J

Jeff

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top