I have a model which has a bytearray as a property,
public byte[] bytearraytest{ get; set; }
when I get this model via javascript GET request it is a string.
tgwBAQ==
How can i decode it now ?
I have a model which has a bytearray as a property,
public byte[] bytearraytest{ get; set; }
when I get this model via javascript GET request it is a string.
tgwBAQ==
How can i decode it now ?
The string in javascript is a Base64 string. You have to do a Base64 Decode in the javascript to access de bytes. Try this: https://www.w3schools.com/jsref/met_win_atob.asp
The string tgwBAQ==
is Base64-encoded (easily discernible via the tell-tale ==
at the end). To get a byte array from that, you would use:
var bytes = Convert.FromBase64String(value);
If you're directly binding that to a byte[]
, it's most likely creating a char[]
, by splitting the string, i.e.:
[ 't', 'g', 'w', 'B', 'A', 'Q', '=', '=' ]
That's fairly obviously useless to you, so first and foremost, you need to accept the value as a string, so you can manipulate it as a string.
Once, you've got a real byte[]
representation of the string, getting back to the IP address string, depends on what occurred previously to Base64-encoding it in the first place. For example, if the provided string was created by doing something like:
var base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(ipAddress));
Then, you would simply reverse that:
var ipAddress = Encoding.UTF8.GetString(Convert.FromBase64String(base64));
However, if encryption was involved, you'd need to decrypt it first, using the same cryptographic algorithm it was encrypted in and the decrypt "key", either an actual shared key, a private key, etc.
Long and short, there's no enough info here to help you with that last piece of the puzzle, so you'll either need to update your question with more information regarding what you're doing or simply take this guidance and run with it on your own.