Use JWT token (JSON Web token) in Android--java

Source: Internet
Author: User

http://blog.csdn.net/mingzhnglei/article/details/51119836

Put a little example on your project.

Importcom.nimbusds.jose.JOSEException;ImportCom.nimbusds.jose.JWSAlgorithm;ImportCom.nimbusds.jose.JWSHeader;ImportCom.nimbusds.jose.JWSObject;ImportCom.nimbusds.jose.JWSSigner;ImportCom.nimbusds.jose.Payload;ImportCom.nimbusds.jose.crypto.MACSigner;ImportNet.minidev.json.JSONObject;/*** Created by Fly0116 on 2016/4/9 0009. * JSON Web Token example*/ Public classExample {StaticString duoshuo_shortname = "Test"; StaticString Duoshuo_secret = "3d990d2276917dfac04467df11fff26d";  Public Static voidmain (String [] args) {jsonobject userInfo=NewJsonobject (); Userinfo.put ("Short_name", duoshuo_shortname);//Required ItemsUserinfo.put ("User_key", "1");//Required ItemsUserinfo.put ("name", "website User A");//options availablePayload Payload=NewPayload (UserInfo); Jwsheader Header=NewJwsheader (jwsalgorithm.hs256); Header.setcontenttype ("JWT"); //Create JWS ObjectJwsobject Jwsobject =NewJwsobject (header, payload); //Create HMAC signerJwssigner signer =NewMacsigner (Duoshuo_secret.getbytes ()); Try{jwsobject.sign (signer); } Catch(joseexception e) {System.err.println ("Couldn ' t sign JWS object:" +e.getmessage ()); return; }        //serialise JWS object to compact formatString token =jwsobject.serialize (); System.out.println ("Serialised JWS object:" +token); //example output is eyjhbgcioijiuzi1niisimn0esi6imp3dcj9.eyj1c2vyx2tlesi6ijeilcjuyw1lijoi572r56uz55so5oi3qsisinnob3j0x25hbwuioij0z Xn0in0.nxkdxwxthzfkyfl_k_-p6mfm5cpofppvfdijrjeq14i    }}

Eight comics understanding design of single sign-on system using JSON Web token

http://blog.leapoahead.com/2015/09/07/user-authentication-with-jwt/

JSON Web Token-securely pass information between Web Apps

http://blog.leapoahead.com/2015/09/06/understanding-jwt/

Use JWT token (JSON Web token) in Android--java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.