添加 token 工具类 TokenUtil

This commit is contained in:
tursom 2019-10-24 22:30:51 +08:00
parent df48998403
commit cdd4dc169b

View File

@ -20,11 +20,7 @@ open class TokenUtil {
val head = type.digestBase64
val body = toJson(TokenBody(System.currentTimeMillis(), timeout, data)).base64()
val encryptSource = "$head.$body".toByteArray()
val encryptKey = secretKey.toByteArray()
encryptSource.forEachIndexed { index, _ ->
encryptSource[index] = encryptSource[index] xor encryptKey[index % encryptKey.size]
}
val encrypt = encryptSource.digest(type.digest)!!.toHexString()
val encrypt = encrypt(secretKey, encryptSource, type.digest)
return "$head.$body.$encrypt"
}
@ -74,4 +70,3 @@ open class TokenUtil {
val instance = TokenUtil()
}
}