1

It's maybe a selly question.. but I'm a bit confused and having a problem in the decoding..

The question is what's the different between this string:

ndE9a8MwEIDhv5JNky1Z/ogrbNNCFkPaoS1dy9lRUoOlc3xn6M vnGQIHToU hOBAvA HKgI3TmaPJ1z41Z4XS7z5sDMN6GuhYyU27a4WnznoDFSmIpXoIlyp jjJ9OEbbUnd9lxfHHkBsvt3oyVyStVhmbxBoIOPBWTLcm7en570JUTPNyNjj GOpEi209MXgOoEqySJXhvCfapLlRhWiqNWguD c74m8BiOzMYQvRfDFPZKSE aYrR2xFPg497dHKtSGcZDsAg03KbPBSVvNNu9Euot7t/0ejAxTDO0HXAj509 o1vpm3INN9fp1y80Pw==

And this one:

ndE9a8MwEIDhv5JNky1Z/ogrbNNCFkPaoS1dy9lRUoOlc3xn6M vnGQIHToU\nhOBAvA HKgI3TmaPJ1z41Z4XS7z5sDMN6GuhYyU27a4WnznoDFSmIpXoIlyp\njjJ9OEbbUnd9lxfHHkBsvt3oyVyStVhmbxBoIOPBWTLcm7en570JUTPNyNjj\nGOpEi209MXgOoEqySJXhvCfapLlRhWiqNWguD c74m8BiOzMYQvRfDFPZKSE\naYrR2xFPg497dHKtSGcZDsAg03KbPBSVvNNu9Euot7t/0ejAxTDO0HXAj509\no1vpm3INN9fp1y80Pw==

I copied both of them from Visual Studio for a string.. The first one from the TextVisualizer:

enter image description here

And the other one from the preview value window:

enter image description here

And how can I get the second first one from the second one?

Edit: Here is my code: This is my code.. Why I'm not able to decode the response?

response = response.Replace("\n", "");
var data = Convert.FromBase64String(response);
var decoder = Encoding.UTF8.GetDecoder();
string encodedString = Encoding.UTF8.GetString(data);

I'm getting this result!

��=k�0�ῒM�-Y��+l�BCڡ-]��QR��s|g�ϯ�d:��@��*7Nf�'\�՞K���3 �k�c%6��9�T�"��"\��2}8F�Rw}��@l����\��Xfoh ��Y2ܛ��� Q3�����D�m=1x�J�H��'ڤ�Q�h�5h.�;�o���a�|1Od��i���O��{tr�Hg� �r�<���n�K�������0��u���=�[�r 7���/4?

Homam
  • 23,263
  • 32
  • 111
  • 187

2 Answers2

0

The Linebreaks and all other control signs are printed in the preview value window :) This is the cause the string is longer

ndE9a8MwEIDhv5JNky1Z/ogrbNNCFkPaoS1dy9lRUoOlc3xn6M vnGQIHToU\nhOBAvA HKgI3TmaPJ1z41Z4XS7z5sDMN6GuhYyU27a4WnznoDFSmIpXoIlyp\njjJ9OEbbUnd9lxfHHkBsvt3oyVyStVhmbxBoIOPBWTLcm7en570JUTPNyNjj\nGOpEi209MXgOoEqySJXhvCfapLlRhWiqNWguD c74m8BiOzMYQvRfDFPZKSE\naYrR2xFPg497dHKtSGcZDsAg03KbPBSVvNNu9Euot7t/0ejAxTDO0HXAj509\no1vpm3INN9fp1y80Pw==

ndE9a8MwEIDhv5JNky1Z/ogrbNNCFkPaoS1dy9lRUoOlc3xn6M vnGQIHToU \n hOBAvA <--

I dont know which Encoding to use in your case, but i works by replacing all \n

var b64 =
  "ndE9a8MwEIDhv5JNky1Z/ogrbNNCFkPaoS1dy9lRUoOlc3xn6M vnGQIHToU\nhOBAvA HKgI3TmaPJ1z41Z4XS7z5sDMN6GuhYyU27a4WnznoDFSmIpXoIlyp\njjJ9OEbbUnd9lxfHHkBsvt3oyVyStVhmbxBoIOPBWTLcm7en570JUTPNyNjj\nGOpEi209MXgOoEqySJXhvCfapLlRhWiqNWguD c74m8BiOzMYQvRfDFPZKSE\naYrR2xFPg497dHKtSGcZDsAg03KbPBSVvNNu9Euot7t/0ejAxTDO0HXAj509\no1vpm3INN9fp1y80Pw==";

var replacedNewLine = b64.Replace("\n", string.Empty);

var decoded = Encoding.Default.GetString(Convert.FromBase64String(replacedNewLine));
Console.WriteLine(decoded);
Console.Read();

Same result with both of your strings

PS: seems to be a not Default Encoding or crypted text.

S.L.
  • 1,056
  • 7
  • 15
  • When I try to decode the first one using this debugger.. it works fine, but the second one isn't working! https://rnd.feide.no/simplesaml/module.php/saml2debug/debug.php – Homam Aug 08 '14 at 12:58
  • you have to set Option with linebreaks or something like that, else the linebreaks are part of the string and make the base64 string invalid ... the first one works because the linebreaks are not printed – S.L. Aug 08 '14 at 13:00
  • 1
    As explaination: base64 string cann be created with an Option "with linebreaks" or somthing like this, and the the base64 string has a fixed line length and Looks like your first string IF you parse the linebreaks \n right. – S.L. Aug 08 '14 at 13:06
  • Thank you S.L. I removed the new line character "\n" but still not able to decode the base64 response. Please check the code in the question. – Homam Aug 08 '14 at 13:11
  • This is exactly my problem.. But I wonder what's the magic that this debugger is doing to decode it! https://rnd.feide.no/simplesaml/module.php/saml2debug/debug.php – Homam Aug 08 '14 at 13:58
  • look here maybe http://stackoverflow.com/questions/6249199/decode-saml-2-0-64base-string – S.L. Aug 08 '14 at 14:00
0

Edit: I misread what your expected output ist.

There is a difference: look for the newline character in the first: "\n". As a guess the Text visualizer is parsing the string in someway and wraps the string at the location of the \n. As for getting this one: Replace all newline characters ("\n") with string.emptyy or "".

Christian Sauer
  • 10,351
  • 10
  • 53
  • 85