Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid character in a base-64 string

Status
Not open for further replies.

tango1948

Programmer
Dec 23, 2006
111
IL
Hi,
I'm using Convert.ToBase64String to encrypt a connection string. On my dev. pc everything works as it should. On the customers machine (with his connection string - which includes password=***** - if that's of intrest) I get:
"invalid character in a base-64 string".
After some searching on the internet, I understand that the base-64 character set may be rather limited.
What convert should I use to encrypt a connection string?
Thanks for any help

David
 
base-64 encodeing is not encrypting! You should check out the classes in System.Security.Cryptography namespace.
 
Thanks for the reply Aptitude
I understand its not encryption but is there a Convert I can
use that wont return this error. ?
 
World domination.

Christiaan Baes
Belgium

"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
Try this: Convert.ToString(connectionString)

Ignore that, I'm being facetious. Either you want to encrypt or you don't!

Seriously though you can't just be passing a connection string to Convert.ToBase64String as it takes a byte array rather than a string as a parameter. Maybe if you give us a little snippit of your code, we could be more helpfull. Also it would be a good idea if you could try the faulty connection string with each of the password's letters removed in turn so that you can narrow down exactly which character is causing the issue.

Lastly are you sure you haven't used Convert.FromBase64String by mistake as this is more likly to be giving the error you are describing.
 
I was looking for info on encrypting a connection string.
I found the following code entitled "Encrypting Connection Strings":

Code:
    Private Sub EncryptBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EncryptBtn.Click
        Dim b() As Byte = ASCIIEncoding.ASCII.GetBytes(toEncryptTxt.Text)
        EncryptedTxt.Text = Convert.ToBase64String(b)
    End Sub

    Private Sub DecryptBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DecryptBtn.Click
        Dim b() As Byte = Convert.FromBase64String(EncryptedTxt.Text)
        toEncryptTxt.Text = ASCIIEncoding.ASCII.GetString(b)
    End Sub
at

I guess i was fooled by the title.

So what method do you suggest for encrypting a connection string? I'm using asp.net 1.1.

Thanks for your help

David
 
They're using the Base64 encoding there to allow them to store a byte array in a .config file, which is a text file not a binary file.

Storing:
Passwordstring -> ByteArray -> Base64String

Retrieving:
Base64String -> ByteArray -> PasswordString

Like others have said, this is obscuring the content, not encrypting it. But it might be good enough for you.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top