question: public String base64UrlEncode ( byte [ ] data ) { String encodedData = new String ( Base64 . encode ( data , Base64 . URL_SAFE ) ) ; encodedData = encodedData . replace ( "=" , "" ) ; encodedData = encodedData . replace ( "\n" , "" ) ; return encodedData ; }
target:  Encodes a String with base64Url encoding It also removes characters which must be removed according to the JOSE spec:  http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-29#appendix-C