Re: Need help decrypting

From: Steve Long (Steve_Noneya_at_NoSpam.com)
Date: 02/23/05


Date: Tue, 22 Feb 2005 15:50:23 -0800

I'm so sorry, I changed the password in Encrypt just before I posted.
Consider that the same in both decrypt and encrypt

Steve

"Steve Long" <Steve_Noneya@NoSpam.com> wrote in message
news:%23$4F0oPGFHA.2032@tk2msftngp13.phx.gbl...
> Hello,
> I'm wondering if somebody can help me figure out how to decrypt data. I
seem
> to be able to encrypt data but have not been able to decrypt the very data
> that I've encrypted. I know it's because I'm just not understanding the
> whole process but I'm obviously just not getting it. Here's the encryption
> function I'm using:
>
> Private Sub Encryptpwd()
> Dim cdk As PasswordDeriveBytes = New PasswordDeriveBytes("passwd",
> Nothing)
> Dim iv() As Byte = {0, 0, 0, 0, 0, 0, 0, 0}
> Dim key() As Byte = cdk.CryptDeriveKey("RC2", "SHA1", 128, iv)
>
> Console.WriteLine(key.Length * 8)
> ' Set up an RC2 object to encrypt with the derived key
> Dim rc2 As RC2CryptoServiceProvider = New RC2CryptoServiceProvider
> rc2.Key = key
> Dim b() As Byte = {21, 22, 23, 24, 25, 26, 27, 28}
> rc2.IV = b
> Dim plaintext() As Byte = Encoding.UTF8.GetBytes("iiMap")
> Dim ms As New MemoryStream
> Dim cs As CryptoStream = New CryptoStream(ms, rc2.CreateEncryptor(),
_
> CryptoStreamMode.Write)
> cs.Write(plaintext, 0, plaintext.Length)
> cs.Close()
> Dim result() As Byte = ms.ToArray()
> Dim asc As New ASCIIEncoding
> txtResult.Text = asc.GetString(result)
> ms.Close()
> End Sub
>
> When I try to decrypt the text that's in txtResult.Text, my result is
always
> and empty string:
>
> Private Sub Decryptpwd()
> Dim cdk As PasswordDeriveBytes = New
> PasswordDeriveBytes("pa[]ss!!wo//dd", Nothing)
> Dim iv() As Byte = {0, 0, 0, 0, 0, 0, 0, 0}
> Dim key() As Byte = cdk.CryptDeriveKey("RC2", "SHA1", 128, iv)
>
> Console.WriteLine(key.Length * 8)
> ' Set up an RC2 object to encrypt with the derived key
> Dim rc2 As RC2CryptoServiceProvider = New RC2CryptoServiceProvider
> rc2.Key = key
> Dim b() As Byte = {21, 22, 23, 24, 25, 26, 27, 28}
> rc2.IV = b
> Dim plaintext() As Byte = Encoding.UTF8.GetBytes(txtResult.Text)
>
> Dim ms As New MemoryStream
> Dim cs As CryptoStream = New CryptoStream(ms, rc2.CreateDecryptor(),
_
> CryptoStreamMode.Write)
> cs.Write(plaintext, 0, plaintext.Length)
> Dim result(plaintext.Length - 1) As Byte
> ms.Read(result, 0, result.Length - 1)
> Dim asc As New ASCIIEncoding
> txtDecrypt.Text = asc.GetString(result)
> cs.Close()
> ms.Close()
> End Sub
>
> I would very much appreciate someone setting me straight on this issue.
> Thanks in advance
> Steve
>
>
>



Relevant Pages

  • Key derivation in c++ and VB.NET
    ... I am trying to encrypt data in c++ and decrypt in VB.NET. ... System.Cryptography classes don't align exactly with the CryptoAPI ... Dim bHash As PasswordDeriveBytes ...
    (microsoft.public.dotnet.security)
  • Ugh, at my whits end and in desperate need of help.
    ... I can create and encrypt a message ... with the public key without a problem, but when I try to decrypt the message ... Dim privatecert As New X509Certificate2 ...
    (microsoft.public.security)
  • Re: PictureBox and images
    ... First you should prepare your images - encrypt them using InitialEncode. ... even number to decrypt). ... Second button to load the image to picturebox. ... Private Sub Command1_Click ...
    (microsoft.public.vb.general.discussion)
  • RSACryptoServiceProvider problem with bad Key
    ... I encrypt using the public key, but when I decrypt using the private key I ... Dim privatecert As New X509Certificates.X509Certificate2 ...
    (microsoft.public.dotnet.security)
  • RE: Cryptography, Encryption, Decryption Help
    ... I changed the Encrypt and Decrypt functions in the Crypto.vb class to take in strings instead of Byte arrays. ... Dim EncryptString As String ...
    (microsoft.public.pocketpc.developer)