0

I want to get proper encoded string value from decoded string.

In my database one column is storing value in this way.

UA8SMvak9gq+mjrj6C6BR9atmlA=

This value is saving from distributed memory caching in database in table.

So I am not sure from where code is generating this string.

Now I want see actual value of this string so I thought it is some Decoded string, so I tried below to see encoded string but that encoded value does not looks good.

byte[] data = Convert.FromBase64String("UA8SMvak9gq+mjrj6C6BR9atmlA=");
string decodedString = Encoding.UTF8.GetString(data);

It's encoded string looks like this :

"P\u000f\u00122���\n��:��.�G֭�P"

Any idea on this Like how I can get proper encoded string.

Charlieface
  • 52,284
  • 6
  • 19
  • 43
Sami In
  • 246
  • 2
  • 11
  • 1
    What makes you think it's a readable string, it might be any string of bytes, such as a hash or encrypted value – Charlieface May 31 '23 at 09:18
  • @Charlieface I just assume it.. I am also not sure which string is this – Sami In May 31 '23 at 09:38
  • Then what's the question? If you don't know what it is, why try to decode it? Why do you care about it? It's just a black box string of characters – Charlieface May 31 '23 at 09:39
  • Actually I want to change that value with something else.. But as it is generating from distributed memory so I am not sure from where it is adding so I will decode it and put condition like if this is userid then update this value to new value – Sami In May 31 '23 at 09:51
  • 1
    I literally didn't understand a word of that. *Actually I want to change that value with something else..* you haven't said anything about changing it, what do you want to change it to, and what's stopping you? *But as it is generating from distributed memory* no idea what tha means. *so I am not sure from where it is adding* Adding?? Is it a number? *so I will decode it* you said you want to change it so why do you care about the existing value? *and put condition like if this is userid* what userid, where does that come from? *then update this value to new value* so just do it? – Charlieface May 31 '23 at 11:31
  • This is almost certainly not a string in any encoding, just a collection of bytes. With a length of 160 bits this may well be a SHA-1 hash. This cannot be turned into the string that produced this hash, but you can SHA-1 hash another string and compare it to see if it was (almost certainly) the original string. – Jeroen Mostert May 31 '23 at 12:28

1 Answers1

0

All common encoding decoded results showed invalid characters. So the original data should be binary data. It might be encrypted string or it might not be string at all.

byte[] data = Convert.FromBase64String("UA8SMvak9gq+mjrj6C6BR9atmlA=");

foreach (EncodingInfo ei in Encoding.GetEncodings())
{
    Encoding e = ei.GetEncoding();
    string decodedString = e.GetString(data);
    Console.WriteLine($"{e.EncodingName}: {decodedString}");
}
ioi
  • 31
  • 2