public bool Verify(string identity, string signature) { var signedTlsCompressed = FromBase64UrlString(signature); var signedTlsByte = ZipHelper.Decompress(signedTlsCompressed); var signedTlsJson = Encoding.UTF8.GetString(signedTlsByte); var signedTls = JsonConvert.DeserializeObject <SignedTls>(signedTlsJson); if (signedTls.Identifier != identity) { return(false); } if (signedTls.AppId != _appId) { return(false); } var signaturedBytes = Convert.FromBase64String(signedTls.Signature); var tls = new Tls() { AccountType = signedTls.AccountType, AppId = signedTls.AppId, AppIdAt3rd = signedTls.AppIdAt3rd, Expired = signedTls.Expired, Identifier = signedTls.Identifier, Time = signedTls.Time }; return(ShaSigner.VerifySha256ECDSA(tls.ToSignContent(), signaturedBytes, _keyChain.PublicKey)); }
public string Sign(string identity) { var tls = new Tls() { AccountType = "0", AppId = _appId, AppIdAt3rd = "0", Expired = _expired, Identifier = identity, Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() }; var content = tls.ToSignContent(); var signedTls = new SignedTls(); signedTls.CopyFromTls(tls); signedTls.Signature = Convert.ToBase64String(ShaSigner.SignSha256ECDSA(content, _keyChain.PrivateKey)); var signedTlsJson = JsonConvert.SerializeObject(signedTls); var signedTlsByte = Encoding.UTF8.GetBytes(signedTlsJson); var signedTlsCompressed = ZipHelper.Compress(signedTlsByte); return(ToBase64UrlString(signedTlsCompressed)); }
public void CopyFromTls(Tls tls) { AccountType = tls.AccountType; AppId = tls.AppId; AppIdAt3rd = tls.AppIdAt3rd; Expired = tls.Expired; Identifier = tls.Identifier; Time = tls.Time; }