2

I have the following string from the client - which is encoded and signed by a certificate based off of a java based SSO 3rd party component

"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0NTIwNTE4NTEsImlhdCI6MTQ1MjA1MTc5MSwiaXNzIjoiaHR0cHM6Ly9vYXV0aC9hcGkvb3BlbmlkL3YxL3Rva2VuIiwiYXVkIjoiZWE2NjExNjctYTRiMC00ZDQ4LWIwZTEtNWRjOTMwMzk5MDgzIiwic3ViIjoiMWQ1ZmIwYjctN2NjMy00MjRkLTg1M2QtMWE5YWNjMzg2YTM5IiwiYXRfaGFzaCI6IkF6dnktNUJoR2NBN0E2UjJqMkEwYWciLCJjX2hhc2giOiJ5dzF0NnpNcVlTbE5ITTNCQmJyemVnIn0.R6x1Hz23eaHr8H2uZSwqRa5MUYTibGl8ymSmh-t7Giep1JaQYVMoAKRonj7dWYnqrg7owEI6rgoYiHGKotiD-TKhNPGCaE3MCVCw0gtLZJ1lLq5b8ZMfInlBTcwgXVvK54ENJ04jYR04pIR6Lxb4vyk1MHEc_vHWBMtJKoQrPhFsOZh99Tq-L5aKEmUA-ygnK4ai_GCeI7Yy4aS6Al4Oa1O3E5DPQMTzd-ZZ_suM-3biHblPa-9oxrPfrwhMDyrYTpAr4yhvYHSVcXotul9AHdIkF7kDDIYo9ABQ6UJgOChGgfEPVZ3iOerPHoy8hSrkl5jgFW3w1to6k5DWBbHs9Q"

For java to c# base64 conversions, I know that the '-' needs to be replaced with '+' and '_' needs to be replaced with '/', plus the additional padding if required using '=' at the end of the string to make it the correct length for decoding -

the decoding can be done at : http://ostermiller.org/calc/encode.html and http://www.motobit.com/util/base64-decoder-encoder.asp?charset=utf-8&acharset=

using UTF-8 Encoding

Decoded String:

{"alg":"RS256","typ":"JWT"}{"exp":1452051851,"iat":1452051791,"iss":"https://oauth/api/openid/v1/token","aud":"ea661167-a4b0-4d48-b0e1-5dc930399083","sub":"1d5fb0b7-7cc3-424d-853d-1a9acc386a39","at_hash":"Azvy-5BhGcA7A6R2j2A0ag","c_hash":"yw1t6zMqYSlNHM3BBbrzeg"}�G�m�hz�k�K
�k�a8�_2�)����z�Ii2�
F���՘�����#�ࡈ��-�4ʄ��   �70%B�H--�u���o�L|��70�uo+�4�8��t����[������r���I*�+>l9�}�:�墄�@2�r�j!�x��ˆ��    x9�N�NC=��Y��7n!۔����~�!0<�a:@������U����}wH�^�2��C�    ����=Vw���<z2���^c�U��[h�NCXdz�

From the decoded as can be seen - I need to extract the "sub" value - the rest can stay as garbage as it doesn't need to be decoded

Problem: the problem is the encoded string has a "." in it. What do i replace the "." with in C# ? I have tried replacing it with + and / which are the only 2 other no character values but it ruins the encoding and I can't get "sub"

Suggestions on what to do with the "." in the encoded base64 ?

1 Answer 1

4

The . is not part of the base 64 encoding, it's just a separator between discrete encoded items.

eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9

decodes to

{"alg":"RS256","typ":"JWT"}

and

eyJleHAiOjE0NTIwNTE4NTEsImlhdCI6MTQ1MjA1MTc5MSwiaXNzIjoiaHR0cHM6Ly9vYXV0aC9hcGkvb3BlbmlkL3YxL3Rva2VuIiwiYXVkIjoiZWE2NjExNjctYTRiMC00ZDQ4LWIwZTEtNWRjOTMwMzk5MDgzIiwic3ViIjoiMWQ1ZmIwYjctN2NjMy00MjRkLTg1M2QtMWE5YWNjMzg2YTM5IiwiYXRfaGFzaCI6IkF6dnktNUJoR2NBN0E2UjJqMkEwYWciLCJjX2hhc2giOiJ5dzF0NnpNcVlTbE5ITTNCQmJyemVnIn0

decodes to

{"exp":1452051851,"iat":1452051791,"iss":"https://oauth/api/openid/v1/token","aud":"ea661167-a4b0-4d48-b0e1-5dc930399083","sub":"1d5fb0b7-7cc3-424d-853d-1a9acc386a39","at_hash":"Azvy-5BhGcA7A6R2j2A0ag","c_hash":"yw1t6zMqYSlNHM3BBbrzeg"}
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, thanks! - it worked, I should have tested that before

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.