Source:
public String generateSignedJWT(String nonce, String audience, RSAPrivateKey privateKey, RSAPublicKey pubKey, X509Certificate cert) throws AuthenticationException { if (StringExtensions.IsNullOrBlank(nonce)) { throw new IllegalArgumentException("nonce"); } if (StringExtensions.IsNullOrBlank(audience)) { throw new IllegalArgumentException("audience"); } if (privateKey == null) { throw new IllegalArgumentException("privateKey"); } if (pubKey == null) { throw new IllegalArgumentException("pubKey"); } Gson gson = new Gson(); Claims claims = new Claims(); claims.mNonce = nonce; claims.mAudience = audience; claims.mIssueAt = (System.currentTimeMillis() / SECONDS_MS); JwsHeader header = new JwsHeader(); header.mAlgorithm = JWS_HEADER_ALG; header.mType = "JWT"; String signingInput; String signature; try { header.mCert = new String[1]; header.mCert[0] = new String(Base64.encode(cert.getEncoded(), Base64.NO_WRAP), AuthenticationConstants.ENCODING_UTF8); String headerJsonString = gson.toJson(header); String claimsJsonString = gson.toJson(claims); Logger.v(TAG, "Client certificate challenge response JWS Header:" + headerJsonString); signingInput = StringExtensions.encodeBase64URLSafeString(headerJsonString .getBytes(AuthenticationConstants.ENCODING_UTF8)) + "." + StringExtensions.encodeBase64URLSafeString(claimsJsonString .getBytes(AuthenticationConstants.ENCODING_UTF8)); signature = sign(privateKey, signingInput.getBytes(AuthenticationConstants.ENCODING_UTF8)); } catch (UnsupportedEncodingException e) { throw new AuthenticationException(ADALError.ENCODING_IS_NOT_SUPPORTED); } catch (CertificateEncodingException e) { throw new AuthenticationException(ADALError.CERTIFICATE_ENCODING_ERROR); } return signingInput + "." + signature; }

Target:
public String generateSignedJWT(String nonce, String audience, RSAPrivateKey privateKey, RSAPublicKey pubKey, X509Certificate cert) throws AuthenticationException { if (StringExtensions.IsNullOrBlank(nonce)) { throw new IllegalArgumentException("nonce"); } if (StringExtensions.IsNullOrBlank(audience)) { throw new IllegalArgumentException("audience"); } if (privateKey == null) { throw new IllegalArgumentException("privateKey"); } if (pubKey == null) { throw new IllegalArgumentException("pubKey"); } Gson gson = new Gson(); Claims claims = new Claims(); claims.mNonce = nonce; claims.mAudience = audience; claims.mIssueAt = (System.currentTimeMillis() / SECONDS_MS); JwsHeader header = new JwsHeader(); header.mAlgorithm = JWS_HEADER_ALG; header.mType = "JWT"; final String signingInput; final String signature; try { header.mCert = new String[1]; header.mCert[0] = new String(Base64.encode(cert.getEncoded(), Base64.NO_WRAP), AuthenticationConstants.ENCODING_UTF8); String headerJsonString = gson.toJson(header); String claimsJsonString = gson.toJson(claims); Logger.v(TAG, "Client certificate challenge response JWS Header:" + headerJsonString); signingInput = StringExtensions.encodeBase64URLSafeString(headerJsonString .getBytes(AuthenticationConstants.ENCODING_UTF8)) + "." + StringExtensions.encodeBase64URLSafeString(claimsJsonString .getBytes(AuthenticationConstants.ENCODING_UTF8)); signature = sign(privateKey, signingInput.getBytes(AuthenticationConstants.ENCODING_UTF8)); } catch (UnsupportedEncodingException e) { throw new AuthenticationException(ADALError.ENCODING_IS_NOT_SUPPORTED); } catch (CertificateEncodingException e) { throw new AuthenticationException(ADALError.CERTIFICATE_ENCODING_ERROR); } return signingInput + "." + signature; }