<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.im
        {mso-style-name:im;}
span.hoenzb
        {mso-style-name:hoenzb;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">My 2 cents:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">There is an openSSL example to verify a jwt:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><a href="https://gist.github.com/rolandyoung/176dd310a6948e094be6">https://gist.github.com/rolandyoung/176dd310a6948e094be6</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">By using jose4j<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // be sure you do not have any EOL at the end of the token<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">String accesToken = …;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">accesToken = accesToken.replaceAll(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;\r\n&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">,
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">accesToken = accesToken.replaceAll(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;\n&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">,
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">JsonWebSignature
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">jws</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> =
</span><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">new</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> JsonWebSignature();</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">jws</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">.setCompactSerialization(accesToken);</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">jws</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">.setKey(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">publicKey</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">boolean signatureVerified = jws.verifySignature();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">To get a PublicKey : if you put the content of the realm public you get from keycloak admin
<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:Consolas;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">public</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> PublicKey
<span style="background:silver;mso-highlight:silver">getPublicKey</span>(String </span>
<span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">fileName</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">) {</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">File
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">f</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> =
</span><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">new</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> File(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">fileName</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">try</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> (FileInputStream
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">fis</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> =
</span><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">new</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> FileInputStream(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">f</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt;text-indent:36.0pt;text-autospace:none">
<span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">DataInputStream
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">dis</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> =
</span><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">new</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> DataInputStream(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">fis</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);)
 {</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">byte</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">[]
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">keyBytes</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> =
</span><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">new</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">
</span><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">byte</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">[(</span><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">int</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">)
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">f</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">.length()];</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">dis</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">.readFully(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">keyBytes</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">dis</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">.close();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // convert to der format<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String pem = new String(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">keyBytes</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> =
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">.replaceAll(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;-----BEGIN (.*)-----&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">,
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> =
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">.replaceAll(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;-----END (.*)----&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">,
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> =
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">.replaceAll(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;\r\n&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">,
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> =
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">.replaceAll(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;\n&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">,
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte[] der = Base64.getDecoder().decode(pem); // java 8<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span lang="FR" style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">X509EncodedKeySpec
</span><span lang="FR" style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">spec</span><span lang="FR" style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> =
</span><b><span lang="FR" style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">new</span></b><span lang="FR" style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> X509EncodedKeySpec(der);</span><span lang="FR" style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="FR" style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">KeyFactory
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">kf</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> = KeyFactory.<i>getInstance</i>(</span><b><i><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#0000C0">RSA</span></i></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">return</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">kf</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">.generatePublic(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">spec</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
</span><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">catch</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> (IOException | InvalidKeySpecException | NoSuchAlgorithmException
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">e</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">) {</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">throw</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">
</span><b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#7F0055">new</span></b><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> RuntimeException(</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;Failed
 to load public key from file '&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> &#43;
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">fileName</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black"> &#43;
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF">&quot;'&quot;</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">,
</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:#6A3E3E">e</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">);</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><span style="font-size:8.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">With Java 8, it is quite simple too<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">String[]&nbsp; tokenParts</span><span style="font-size:8.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"> &nbsp;=
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">accessToken.split(&quot;\\.&quot;);</span><span style="font-size:8.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt"><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">// detect algo from tokenParts[0] or put &quot;SHA256withRSA” (for “RS256”)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">String jwtSignAlgo = &quot;SHA256withRSA&quot;;
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String jwtInputString = tokenParts[0] &#43; “.” &#43; tokenParts[1];<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String jwtDecodedSign = new String(Base64.getUrlDecoder().decode(tokenParts[2]);</span><span style="font-size:8.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span lang="FR" style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">Signature verifier = Signature.getInstance(jwtSignAlgo);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="FR" style="font-size:8.0pt;font-family:Consolas;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">verifier</span><span style="font-size:8.0pt;font-family:Consolas;color:black">.initVerify(</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">publicKey</span><span style="font-size:8.0pt;font-family:Consolas;color:black">);</span><span style="font-size:8.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:Consolas;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">verifier</span><span style="font-size:8.0pt;font-family:Consolas;color:black">.update(</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">jwtInputString</span><span style="font-size:8.0pt;font-family:Consolas;color:black">.getBytes(&quot;UTF-8&quot;));</span><span style="font-size:8.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:Consolas;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; boolean
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">signatureVerified</span><span style="font-size:8.0pt;font-family:Consolas;color:black"> =
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">verifier</span><span style="font-size:8.0pt;font-family:Consolas;color:black">.verify(</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">jwtDecodedSign</span><span style="font-size:8.0pt;font-family:Consolas;color:black">);</span><span style="font-size:8.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">gerard<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> keycloak-user-bounces@lists.jboss.org [mailto:keycloak-user-bounces@lists.jboss.org]
<b>On Behalf Of </b>Stian Thorgersen<br>
<b>Sent:</b> vendredi 6 mai 2016 07:33<br>
<b>To:</b> Aikeaguinea<br>
<b>Cc:</b> keycloak-user<br>
<b>Subject:</b> Re: [keycloak-user] Validating JWT tokens<o:p></o:p></span></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal">On 4 May 2016 at 18:37, Aikeaguinea &lt;<a href="mailto:aikeaguinea@xsmail.com" target="_blank">aikeaguinea@xsmail.com</a>&gt; wrote:<o:p></o:p></p>
<p class="MsoNormal">Figured it out, kinda. I have to use the Realm public key, and at least<br>
in <a href="http://jwt.io" target="_blank">jwt.io</a> it has to begin with &quot;-----BEGIN PUBLIC KEY-----&quot; and end with<br>
&quot;-----END PUBLIC KEY-----&quot; -- these can't be omitted.<br>
<br>
If I try using the Realm certificate, it won't work, however, whether or<br>
not I use &quot;-----BEGIN CERTIFICATE-----&quot;/&quot;-----END CERTIFICATE-----&quot;.<br>
<br>
If I use the validator at <a href="http://kjur.github.io/jsjws/tool_jwt.html" target="_blank">
http://kjur.github.io/jsjws/tool_jwt.html</a> and<br>
select &quot;default X509 Certificate (RSA z4) it tells me &quot;Error: malformed<br>
X.509 certificate PEM (code:003)&quot;<br>
<br>
I can use the Realm public key for validating the JWT, but shouldn't the<br>
certificate work as well?<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">The certificate is only used by SAML, so no you can't verify the JWT with the certificate only the public key.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">&nbsp;<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal"><br>
<span class="im">On Wed, May 4, 2016, at 12:00 PM, Aikeaguinea wrote:</span><br>
<span class="im">&gt; I have a client with a service account and credentials using Signed Jwt.</span><br>
<span class="im">&gt; Authentication works fine. The service uses</span><br>
<span class="im">&gt; org.keycloak.adapters.authentication.ClientCredentialsProviderUtils#setClientCredentials</span><br>
<span class="im">&gt; to create the JWT token and set the headers, and I get back a JWT</span><br>
<span class="im">&gt; containing an access token from Keycloak.</span><br>
<span class="im">&gt;</span><br>
<span class="im">&gt; However, when I use <a href="http://jwt.io" target="_blank">jwt.io</a> to look at the access token, I can't validate</span><br>
<span class="im">&gt; the signature. This is true whether I use the client Certificate (from</span><br>
<span class="im">&gt; the client's Credentials tab), the Realm public key, or the Realm</span><br>
<span class="im">&gt; Certificate. In addition, I have generated the client's public key from</span><br>
<span class="im">&gt; the certificate using</span><br>
<span class="im">&gt;</span><br>
<span class="im">&gt; keytool -exportcert -alias x -keypass y -storepass z -rfc -keystore</span><br>
<span class="im">&gt; client-keystore.jks | openssl x509 -inform pem -pubkey</span><br>
<span class="im">&gt;</span><br>
<span class="im">&gt; on the jks file supplied when I generated the client credentials, and</span><br>
<span class="im">&gt; that doesn't work either.</span><br>
<span class="im">&gt;</span><br>
<span class="im">&gt; We've also been having trouble validating the signature programmatically</span><br>
<span class="im">&gt; using Java.</span><br>
<span class="im">&gt;</span><br>
<span class="im">&gt; Any idea why I might be seeing this?</span><br>
<span class="im">&gt;</span><br>
<span class="im">&gt; --</span><br>
<span class="im">&gt; <a href="http://www.fastmail.com" target="_blank">http://www.fastmail.com</a> - Or how I learned to stop worrying and</span><br>
<span class="im">&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;love email again</span><br>
<span class="im">&gt;</span><br>
<br>
<br>
<span class="hoenzb"><span style="color:#888888">--</span></span><span style="color:#888888"><br>
<span class="hoenzb">&nbsp; Aikeaguinea</span><br>
<span class="hoenzb">&nbsp; <a href="mailto:aikeaguinea@xsmail.com">aikeaguinea@xsmail.com</a></span><br>
<br>
<span class="hoenzb">--</span><br>
<span class="hoenzb"><a href="http://www.fastmail.com" target="_blank">http://www.fastmail.com</a> - Send your email first class</span></span><o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><br>
_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</div>
</div>
</body>
</html>