Question

I am coding an application where I send parameters in a URL, but I want these parameters to be encrypted so the user wont understand how the process works.

I chose Base 64

So, I wrote the function that reads Base 64 off the URL and converts it to string. Here it is:

 Public Sub FromBase64ToString(ByVal s As String)
        Dim base64Encoded As String = s
        Dim base64Decoded As String
        Dim data() As Byte
        data = System.Convert.FromBase64String(base64Encoded)
        base64Decoded = System.Text.ASCIIEncoding.ASCII.GetString(data)
 End Sub

But what I need is a function that converts String to Base 64 from the side where I form and send the URL to the user.

Where can I find the function that does that?

And Does anyone suggest anything other than base64?

The parameter Im encoding is numeric only.

Was it helpful?

Solution

The logic on the opposite end of that would look like this:

Dim base64Encoded As String = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(plainText))

As mentioned in the comments above, though, ASCII will only work for a small set of (mostly English) characters, so if you need it to handle any string, it would be better to use Encoding.Unicode. Also, base-64 is just a different encoding scheme. It is not an encryption method. Most technically inclined people would recognize that it's base-64 and be able to decode it easily. If that's not an issue, that's fine, but if you really want to make it secure, you need to use an actual encryption algorithm, such as AES.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top