1

I am using AES CBC encryption in VB.Net and decryption is done using AS3Crypto. First few characters (about 16) are missing during decryption and replaced with random characters like below.

05[ÚðÊ\ÃPôôÄ]óbR

Here is my .net code. On AS3Crypto demo page, I use Secret Key > AES > CBC. I tried with different settings for Padding and Key Formats still no luck.

Thanks.

Dim plainText = txt2encrypt.Text.Trim

    Dim encrypted() As Byte        '
    Using aesAlg As New AesCryptoServiceProvider()

        aesAlg.Mode = CipherMode.CBC

        ' Create a decrytor to perform the stream transform. 
        Dim encryptor As ICryptoTransform = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV)
        ' Create the streams used for encryption. 
        Using msEncrypt As New MemoryStream()
            Using csEncrypt As New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)
                Using swEncrypt As New StreamWriter(csEncrypt)

                    'Write all data to the stream.
                    swEncrypt.Write(plainText)
                End Using
                encrypted = msEncrypt.ToArray()
            End Using
        End Using

        Dim encryptedText = Convert.ToBase64String(encrypted)

        txtkey.Text = Convert.ToBase64String(aesAlg.Key)
        txtiv.Text = Convert.ToBase64String(aesAlg.IV)
        txtkeysize.Text = aesAlg.KeySize
        txtencrypted.Text = encryptedText
        txtpadding.Text = aesAlg.Padding

    End Using
Laurence
  • 7,633
  • 21
  • 78
  • 129
  • If you use an incorrect IV value during decryption it will ruin the first sixteen bytes of data. Is it possible this has happened in your case? Maybe you should post the code that interacts with AS3Crypto. – Duncan Jones Jun 26 '13 at 15:48
  • Hi Duncan, Thanks for your reply. I have solved this problem by puting IV prefix while encryption and setting AS3crypto to look for IV on the start of the encryptedstring. But I still have problem with decryption in .Net which encrypted in AS3crypto. Perhaps, you can help me with that? please see my new question i posted today. Thanks a lot. – Laurence Jun 26 '13 at 15:53
  • 2
    Please either post a solution to this question or delete it. As it stands, it's now a dangling unanswered question. – Duncan Jones Jun 26 '13 at 16:03
  • Thanks Duncan, what will happen if i delete this post? I tried deleting my posts before, it didn't delete the post but marked as voted to delete. – Laurence Jun 26 '13 at 16:44
  • If there are no answers, it will be deleted. Preferably, you should answer your own question for the benefit of future readers. – Duncan Jones Jun 27 '13 at 06:54

0 Answers0