Пример #1
0
        public string GetJwt <T>(T claimsObject)
        {
            var certLocation = _certs.Last();
            var cert         = new X509Certificate2(_certData.GetValueOrDefault(certLocation) ?? new byte[] {}, _certPassword.GetValueOrDefault(certLocation));

            var rsa = cert.GetRSAPrivateKey();

            var key = new RsaSecurityKey(rsa)
            {
                KeyId = cert.Thumbprint
            };

            var signingCredentials = new SigningCredentials(key,
                                                            SecurityAlgorithms.RsaSha512, SecurityAlgorithms.RsaSha512);

            var header = new JwtHeader(signingCredentials).Base64UrlEncode();

            var body = Base64UrlEncoder.Encode(JsonSerializer.SerializeToUtf8Bytes(claimsObject));

            var firstParts = header + "." + body;

            var signature = JwtTokenUtilities.CreateEncodedSignature(firstParts, signingCredentials);

            return(firstParts + "." + signature);
        }
Пример #2
0
        public void FindKeyMatch(KeyMatchTheoryData theoryData)
        {
            var context = TestUtilities.WriteHeader($"{this}.SegmentCanRead", theoryData);

            try
            {
                var matchKey = JwtTokenUtilities.FindKeyMatch(theoryData.Kid, theoryData.X5t, theoryData.SecurityKey, theoryData.SecurityKeys);
                if (!object.ReferenceEquals(matchKey, theoryData.Match))
                {
                    context.Diffs.Add("!object.ReferenceEquals(matchKey, theoryData.Match)");
                }

                theoryData.ExpectedException.ProcessNoException(context);
            }
            catch (Exception ex)
            {
                theoryData.ExpectedException.ProcessException(ex, context);
            }

            TestUtilities.AssertFailIfErrors(context);
        }