simple encrypting / decrypting in VB.Net

后端 未结 4 1138
执笔经年
执笔经年 2020-12-28 10:55

I\'m trying to figure out how to encrypt / decrypt a string in VB.Net.

I followed the example given here and wrote the following code (below). There\'s a text box,

4条回答
  •  梦谈多话
    2020-12-28 11:32

    The issue I spotted is on this line in your encryption code:

    Me.TextBox1.Text = Me.enc.GetString(ms.ToArray())

    The problem is that this assumes your byte array already is a UTF-8 string, just carved up as a byte array, when in fact it should be random bytes and likely includes unprintable characters. It's not valid utf-8 data. What you want to do instead is base-64 encode that byte array using the Convert.ToBase64String() function.

    Then, your decryption needs to correctly convert that base 64 string back to a byte array, using the Convert.FromBase64String() method.

提交回复
热议问题