Reputation: 543
I need to encrypt decrypt a string. using base 64 with custom characters well one custom character chr(255) (-). I would like to use the built in ,net FromBase64String but it errors with invalid characters. If i use the below code (see link) and change the character / to - it works. Any ideas to make this work using .nets built in functions.
http://www.freevbcode.com/ShowCode.asp?ID=5248.
Thanks all
Upvotes: 0
Views: 106
Reputation: 133995
This is normally done with a function that does a string.Replace
, like this:
public string CustomToBase64String(byte[] data)
{
var s = Convert.ToBase64String(data);
return s.Replace('/', (char)255);
}
public byte[] CustomFromBase64String(string s)
{
var changed = s.Replace((char)255, '/');
return Convert.FromBase64String(s);
}
Upvotes: 1