mirror of
https://github.com/tursom/TursomServer.git
synced 2025-02-01 07:11:18 +08:00
添加 token 工具类 TokenUtil
This commit is contained in:
parent
df48998403
commit
cdd4dc169b
@ -20,11 +20,7 @@ open class TokenUtil {
|
|||||||
val head = type.digestBase64
|
val head = type.digestBase64
|
||||||
val body = toJson(TokenBody(System.currentTimeMillis(), timeout, data)).base64()
|
val body = toJson(TokenBody(System.currentTimeMillis(), timeout, data)).base64()
|
||||||
val encryptSource = "$head.$body".toByteArray()
|
val encryptSource = "$head.$body".toByteArray()
|
||||||
val encryptKey = secretKey.toByteArray()
|
val encrypt = encrypt(secretKey, encryptSource, type.digest)
|
||||||
encryptSource.forEachIndexed { index, _ ->
|
|
||||||
encryptSource[index] = encryptSource[index] xor encryptKey[index % encryptKey.size]
|
|
||||||
}
|
|
||||||
val encrypt = encryptSource.digest(type.digest)!!.toHexString()
|
|
||||||
return "$head.$body.$encrypt"
|
return "$head.$body.$encrypt"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,4 +70,3 @@ open class TokenUtil {
|
|||||||
val instance = TokenUtil()
|
val instance = TokenUtil()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user