0

I am trying to decrypt some texts and getting this error. I did google a lot and read articles. There are a lot of people with the same error but I can't solve mine.

Below is some code sample and you can see the IV that I am using.

The IV is produced by AS3crypto. you can see the demo in this page. you can see on Secret Key tab. My setting is AES, CBC.

i.e. I can't change the IV and i think that IV is a valid one.

I think the problem is the way I am setting IV in .Net which isn't right.

Any thoughts guys?

Thanks in advance.

Using aesAlg As New AesCryptoServiceProvider

       Dim IV_COMPONENT As Byte() = Convert.FromBase64String("a462114bca101105db976158381a4d05")
       //Dim IV_COMPONENT As Byte() = Encoding.ASCII.GetBytes("a462114bca101105db976158381a4d05")

        aesAlg.IV = IV_COMPONENT

        aesAlg.Mode = CipherMode.CBC

        ' Create a decrytor to perform the stream transform. 
        Dim decryptor As ICryptoTransform = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV)

          Using msDecrypt As New MemoryStream(cipherText)

            Using csDecrypt As New CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)

                Using srDecrypt As New StreamReader(csDecrypt)

                    plaintext = srDecrypt.ReadToEnd()
                End Using
            End Using
        End Using
    End Using
Laurence
  • 7,633
  • 21
  • 78
  • 129

1 Answers1

0

Try a different string encoding. While I used base64 string same as you in my class, I had control over the IV generation and encoding. Perhaps wherever you got the string encoded form of the IV byte array from used UTF8 or some such.

I think I read somewhere that there are only certain byte array lengths that are used as IV's. One way to check would be to get a byte array from that string in various encodings and use the byte array that most closely resembles a power of 2 (128, 256... or 192 since that's also a common magic number).

welegan
  • 3,013
  • 3
  • 15
  • 20