Esempio n. 1
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
            string line;

            using (StreamReader sr = new StreamReader("Questions.json"))
            {
                // Read the stream to a string, and write the string to the console.
                line = sr.ReadToEnd();
            }
            sign = HashSignatureProvider.CreateHS512("upoOddMBrzPEoqlNk7EQrrw9Uqr_cK8Xpp-sI40HYTdflX8hBJsGynX_VLOyN8pAnwN9ILf5jFqz0pjf5YkBDRBwoOJg_O6arngYqgjPO0JSdIfh1GGn1s1UcCkT_rKIb06smL85rn7s9QjhlAN8uvrwm9rIxaMbsMqxZAwb6iNC8F00hqQ2AhDY1Jm48kHAyPUgXgSpahkHiy2six8JsnQknEGAJDNc0wDp2PPedfQUIu-qndpIOeixaesrg9KoATpaRlj1TTlg9ul_LOHbafQZ2Hq1qZHA-OgannyDLP0VTLbyHXIOiesuxvuBvDnQgdGirk96qPoBwWYkVZsW4g");
            quiz = Quiz.FromJson(line);
        }
Esempio n. 2
0
        public override void Process()
        {
            var codeTokenReq = new CodeTokenRequest(new CodeTokenRequestBody
            {
                Code = "hijklmn\r\nopq\trst"
            }, "abcd", "efg")
            {
                ScopeString = "test plain"
            };
            var tokenUrl = codeTokenReq.ToJsonString();

            codeTokenReq = CodeTokenRequest.Parse(tokenUrl);
            tokenUrl     = codeTokenReq.ToQueryData().ToString();
            codeTokenReq = CodeTokenRequest.Parse(tokenUrl);
            tokenUrl     = codeTokenReq.ToJsonString();
            codeTokenReq = CodeTokenRequest.Parse(tokenUrl);
            ConsoleLine.WriteLine(codeTokenReq.ToQueryData().ToString());
            ConsoleLine.WriteLine();

            // JWT HS512
            var hs  = HashSignatureProvider.CreateHS512("a secret string");
            var jwt = new JsonWebToken <HttpClientVerb.NameAndDescription>(new HttpClientVerb.NameAndDescription
            {
                Name        = "abcd",
                Description = "efg"
            }, hs);
            var header = jwt.ToAuthenticationHeaderValue();

            jwt = JsonWebToken <HttpClientVerb.NameAndDescription> .Parse(header.ToString(), hs);

            var jwtStr = jwt.ToEncodedString();

            ConsoleLine.WriteLine(jwtStr != header.Parameter ? "Failed JWT HS512 testing." : jwtStr);
            ConsoleLine.WriteLine();

            // RSA.
            var rsa        = RSA.Create();
            var privateKey = rsa.ExportParameters(true).ToPrivatePEMString(true);

            ConsoleLine.WriteLine(privateKey);
            var publicKey = rsa.ExportParameters(false).ToPublicPEMString();

            ConsoleLine.WriteLine(publicKey);
            var privateKeyP = RSAParametersConvert.Parse(privateKey).Value;
            var privateKeyS = privateKeyP.ToPrivatePEMString(true);
            var publicKeyP  = RSAParametersConvert.Parse(publicKey).Value;
            var publicKeyS  = publicKeyP.ToPublicPEMString();

            ConsoleLine.WriteLine("They are {0}.", (privateKey == privateKeyS) && (publicKey == publicKeyS) ? "same" : "different");
            ConsoleLine.WriteLine();

            // JWT RS512
            using (var rs = RSASignatureProvider.CreateRS512(rsa))
            {
                jwt    = new JsonWebToken <HttpClientVerb.NameAndDescription>(jwt.Payload, rs);
                header = jwt.ToAuthenticationHeaderValue();
                jwt    = JsonWebToken <HttpClientVerb.NameAndDescription> .Parse(header.ToString(), rs);

                jwtStr = jwt.ToEncodedString();
                ConsoleLine.WriteLine(jwtStr != header.Parameter ? "Failed JWT RS512 testing." : header.Parameter);
                ConsoleLine.WriteLine();
            }
        }