build.gradle (:app)
api 'io.jsonwebtoken:jjwt-api:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2'
runtimeOnly('io.jsonwebtoken:jjwt-orgjson:0.11.2') {
exclude group: 'org.json', module: 'json'//provided by Android natively
}
create json web token
// 12시간
val expiration = System.currentTimeMillis() + 12 * (60 * 60 * 1000)
val base64EncodedSecretKey = "your_secretKey_abcdefghijklmn=="
val builder = Jwts.builder()
.signWith(SignatureAlgorithm.forName("HS256"), base64EncodedSecretKey)
.setIssuedAt(Date())
.setExpiration(Date(expiration))
.claim("userId", userId)
.claim("name", userName)
.claim("gender", gender)
.claim("age", age)
.claim("userScore", userScore)
val jwt = builder.compact()
tvJwt.text = jwt
'프로그래밍 > android' 카테고리의 다른 글
android ExoPlayer PlayerView Corner Rounded (0) | 2022.02.28 |
---|---|
android ActionBar MenuItem uppercase issue (0) | 2022.02.28 |
[android] Android 12 Vibrator Pattern(진동 패턴) VibratorManager VIBRATOR_MANAGER_SERVICE (0) | 2022.01.05 |
[android] apk decompile (안드로이드 apk 디컴파일) (0) | 2021.11.30 |
[Android 12] Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE (0) | 2021.11.18 |