title: Encode JWT token in Oracle PL/SQL
body: <p>I want to use a JWT to inatialise a meeting room in Jitsi.
  Our software will create the correct url for the user so it can join the meeting.
  Only users with the correct token can start a meeting.</p>
  
  <p>The url is created with pl/sql. For the example of a valid token i use the website jwt.io.
  I wrote the following code to create the token.
  The first part of the token is correct. Only the signature doesn't match. I think i'm missing a typecast or variable l_content has the wrong type.
  What am i doing wrong?</p>
  
  <pre><code>                    l_token varchar2(30000);
                      l_header varchar2(1000);
                      l_header_base64  raw (1000);
  
                      l_payload varchar2(10000);
                      l_payload_base64  raw(10000);
  
                      l_signature varchar2(30000);
                      l_secretkey string(32767) :='your-256-bit-secret';
                      l_content string(32767);
                                      l_content_raw raw(30000);
                      l_point raw(1);
  
                      l_charset varchar2(8) := 'AL32UTF8';
                      l_crlf varchar2(2) := chr(13) || chr(10);
  
                      l_pay_clean varchar2(10000);
                      l_hdr_clean varchar2(10000);
  
  
  
          begin
              sys.dbms_output.put_line('Token from JWT.io: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c');
              l_point := utl_i18n.string_to_raw( '.', l_charset);
              --
                      --
                      -- maak header middels json en base64 encode
                      select json_object ('alg'  value 'HS256'
                                         ,'typ'  value 'JWT')
                      into   l_header
                      from dual;
  
                      select json_object ('sub'  value '1234567890'
                                          ,'name'  value 'John Doe'
                                          ,'iat'  value 1516239022)
                      into   l_payload
                      from dual;
  
                       l_header_base64  := utl_encode.base64_encode(utl_raw.cast_to_raw(l_header));
                       l_payload_base64 := utl_encode.base64_encode(utl_raw.cast_to_raw(l_payload));
  
                      l_hdr_clean := replace(replace(utl_raw.cast_to_varchar2(l_header_base64),l_crlf), '==');
                      l_pay_clean := replace(replace(utl_raw.cast_to_varchar2(l_payload_base64),l_crlf), '==');
                      sys.dbms_output.put_line('l_hdr_clean: ' || l_hdr_clean);
                      sys.dbms_output.put_line('l_pay_clean: ' || l_pay_clean);
  
                      l_content  := l_hdr_clean || '.' ||l_pay_clean;
                      sys.dbms_output.put_line('l_content: ' || l_content);
  
                      l_signature  := dbms_crypto.mac(UTL_I18N.string_to_raw(l_content, l_charset)
                                                      ,dbms_crypto.hmac_sh256
                                                      ,utl_i18n.string_to_raw(l_secretkey, l_charset));
  
                      sys.dbms_output.put_line('l_signature:' || l_signature);
  
                      return l_hdr_clean||'.'||l_pay_clean||'.'||l_signature;
          end;
  </code></pre>