public static AccessToken Decrypt(string token, string encryptionPrivateKey = "") { var version = token.Substring(0, 3); TokenPackContent packContent = new TokenPackContent(); var buffer = new ByteBuf(Convert.FromBase64String(token.Substring(3))); packContent.unmarshal(buffer); var newToken = new AccessToken() { UserId = Encoding.UTF8.GetString(packContent.uid), UserName = Encoding.UTF8.GetString(packContent.uname), UserType = (int)packContent.utype, Timestamp = (int)packContent.ts }; var claimMessage = new ClaimContent(); claimMessage.unmarshal(new ByteBuf(packContent._messageRawContent)); newToken.Claims = claimMessage; var sign = generateSignature(encryptionPrivateKey, newToken.UserId, newToken.UserName, newToken.UserType, newToken.Timestamp); if (Convert.ToBase64String(sign) != Convert.ToBase64String(packContent.signature)) { throw new Exception("sign verify fail"); } return(newToken); }
public AccessToken() { Claims = new ClaimContent(); }