public IActionResult Success()
        {
            // Get;
            Chilkat.PublicKey pubKey = new Chilkat.PublicKey();
            bool success             = pubKey.LoadFromFile("qa_data/pem/rsa_public.pem");

            Chilkat.Jwt jwt = new Chilkat.Jwt();

            string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";

            //  First verify the signature.
            bool sigVerified = jwt.VerifyJwtPk(token, pubKey);

            Console.WriteLine("verified: " + Convert.ToString(sigVerified));

            int  leeway     = 60;
            bool bTimeValid = jwt.IsTimeValid(token, leeway);

            Console.WriteLine("time constraints valid: " + Convert.ToString(bTimeValid));

            //  Now let's recover the original claims JSON (the payload).
            string payload = jwt.GetPayload(token);

            //  The payload will likely be in compact form:
            Console.WriteLine(payload);

            //  We can format for human viewing by loading it into Chilkat's JSON object
            //  and emit.
            Chilkat.JsonObject json = new Chilkat.JsonObject();
            success          = json.Load(payload);
            json.EmitCompact = false;
            Console.WriteLine(json.Emit());

            //  We can recover the original JOSE header in the same way:
            string joseHeader = jwt.GetHeader(token);

            //  The payload will likely be in compact form:
            Console.WriteLine(joseHeader);

            //  We can format for human viewing by loading it into Chilkat's JSON object
            //  and emit.
            success          = json.Load(joseHeader);
            json.EmitCompact = false;
            Console.WriteLine(json.Emit());
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
            // JwtDecode Test1=new JwtDecode();
            // var x=Test1.GetName("eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJJU1MiLCJzY29wZSI6Imh0dHBzOi8vbGFyaW0uZG5zY2UuZG91YW5lL2NpZWxzZXJ2aWNlL3dzIiwiYXVkIjoiaHR0cHM6Ly9kb3VhbmUuZmluYW5jZXMuZ291di5mci9vYXV0aDIvdjEiLCJpYXQiOiJcL0RhdGUoMTQ2ODM2MjU5Mzc4NClcLyJ9");
            // // var x= Test1.TestJwtSecurityTokenHandler("CfDJ8JJa5feBk79Hq8LMUg4HHXfoWI4CgZu7vOhujmhfwtEi7rYOFiVzoUBGec1HXm2aOD69Q8AEqARSHvCmyUJAw_opdjsSfIhJS3v-Dbe0MsLw8QvdMMOuNeqEZvB93lH03TM62plyHreR5_D_G7kkvJvg5vaMUOd_GgZMRFkLMlrrcrPM8l2jOVOgD1r4WIEr0oCm9KB_T0Bt5vZ37CnPJJt7r6_yVM5yuAZU3aI92S5EYodHHhVe_OjRDqg1nALC2a2KzHbGnBKfO-7FbyocHU0QRdkl5F5VBRJVsHHNMOZJ3jUhtfflSggP_b5Imk0qNcs39rEUUC8ajLUv3zaFxaCTX6yyj-kqYg2JKYFSw7OXQZl_XiNlB2mY9cdb1xjjpbLM4SxWzB8k1rMMkXETK1ZLFpu9DUiDgoKmTqICaduGdETRjvBsVA4fa2H2ztmNWCEL7huxL41rXjYb4jXSosJ6wLpjFp2j9f1oLymvPVKeeZ_aKaxFHIJF_dUnG-nIuPUtCSAexfp4NLiWaR3ctWvQ4NKeRv-UwaBoSrSt_gSJ3QAqafrmu-vTdwIek6xPb9AWTUAC7TWCgIHgz3pQqJKnPteVWgXXsPSizg2FlcWc5kYTa0PV2kf8g7JYKHPbYPkbjDKUAiYoOG4AkFdV5z6febxVZiC4XQZLM3tZHCBUdTaFHJOwUSOX8aWna-BJBA");
            // // var x= Test1.TestJwtSecurityTokenHandler();
            // System.Console.WriteLine(x);
            // var jwt = "eyJhbGciOiJQUzM4NCIsImtpZCI6ImJpbGJvLmJhZ2dpbnNAaG9iYml0b24uZXhhbXBsZSJ9.SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IHlvdXIgZG9vci4gWW91IHN0ZXAgb250byB0aGUgcm9hZCwgYW5kIGlmIHlvdSBkb24ndCBrZWVwIHlvdXIgZmVldCwgdGhlcmXigJlzIG5vIGtub3dpbmcgd2hlcmUgeW91IG1pZ2h0IGJlIHN3ZXB0IG9mZiB0by4.cu22eBqkYDKgIlTpzDXGvaFfz6WGoz7fUDcfT0kkOy42miAh2qyBzk1xEsnk2IpN6-tPid6VrklHkqsGqDqHCdP6O8TTB5dDDItllVo6_1OLPpcbUrhiUSMxbbXUvdvWXzg-UD8biiReQFlfz28zGWVsdiNAUf8ZnyPEgVFn442ZdNqiVJRmBqrYRXe8P_ijQ7p8Vdz0TTrxUeT3lm8d9shnr2lfJT8ImUjvAA2Xez2Mlp8cBE5awDzT0qI0n6uiP1aCN_2_jLAeQTlqRHtfa64QQSUmFAAjVKPbByi7xho0uTOcbH510a6GYmJUAfmWjwZ6oD4ifKo8DYM-X72Eaw";
            // var handler = new JwtSecurityTokenHandler();
            // var token = handler.ReadJwtToken(jwt);
            // System.Console.WriteLine(token);

            System.Console.WriteLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            // int? y=HttpContext.Session.GetInt32("userid");
            CryptoEngine Encrypter = new CryptoEngine();

            // if (y==null){
            //     return RedirectToAction("Index");
            // }
            // bool Exists=dbContext.users.Any(e=>e.UserId==(int)y);
            // if(Exists==false){
            //     return RedirectToAction("Index");
            // }
            // ViewBag.UserId=(int)y;
            ViewBag.UserId = 5;

            List <Photos> Allphoto = dbContext.photos.ToList();

            foreach (var photo in Allphoto)
            {
                photo.Desc      = Encrypter.Decrypt(photo.Desc);
                photo.PhotoPath = Encrypter.Decrypt(photo.PhotoPath);
            }
            ViewBag.AllPhotos = Allphoto;
            return(View());
        }
Esempio n. 2
0
        public static void ECC_SHared_secret()
        {
            bool success;

            //  -----------------------------------------------------------------
            //  (Client-Side) Generate an ECC key, save the public part to a file.
            //  -----------------------------------------------------------------
            Chilkat.Prng       prngClient    = new Chilkat.Prng();
            Chilkat.Ecc        eccClient     = new Chilkat.Ecc();
            Chilkat.PrivateKey privKeyClient = eccClient.GenEccKey("secp256r1", prngClient);
            if (eccClient.LastMethodSuccess != true)
            {
                Console.WriteLine(eccClient.LastErrorText);
                return;
            }

            Chilkat.PublicKey pubKeyClient = privKeyClient.GetPublicKey();
            pubKeyClient.SavePemFile(false, "qa_output/eccClientPub.pem");

            //  -----------------------------------------------------------------
            //  (Server-Side) Generate an ECC key, save the public part to a file.
            //  -----------------------------------------------------------------
            Chilkat.Prng       prngServer    = new Chilkat.Prng();
            Chilkat.Ecc        eccServer     = new Chilkat.Ecc();
            Chilkat.PrivateKey privKeyServer = eccServer.GenEccKey("secp256r1", prngServer);
            if (eccServer.LastMethodSuccess != true)
            {
                Console.WriteLine(eccServer.LastErrorText);
                return;
            }

            Chilkat.PublicKey pubKeyServer = privKeyServer.GetPublicKey();
            pubKeyServer.SavePemFile(false, "qa_output/eccServerPub.pem");

            //  -----------------------------------------------------------------
            //  (Client-Side) Generate the shared secret using our private key, and the other's public key.
            //  -----------------------------------------------------------------

            //  Imagine that the server sent the public key PEM to the client.
            //  (This is simulated by loading the server's public key from the file.
            Chilkat.PublicKey pubKeyFromServer = new Chilkat.PublicKey();
            pubKeyFromServer.LoadFromFile("qa_output/eccServerPub.pem");
            string sharedSecret1 = eccClient.SharedSecretENC(privKeyClient, pubKeyFromServer, "base64");

            //  -----------------------------------------------------------------
            //  (Server-Side) Generate the shared secret using our private key, and the other's public key.
            //  -----------------------------------------------------------------

            //  Imagine that the client sent the public key PEM to the server.
            //  (This is simulated by loading the client's public key from the file.
            Chilkat.PublicKey pubKeyFromClient = new Chilkat.PublicKey();
            pubKeyFromClient.LoadFromFile("qa_output/eccClientPub.pem");
            string sharedSecret2 = eccServer.SharedSecretENC(privKeyServer, pubKeyFromClient, "base64");

            //  ---------------------------------------------------------
            //  Examine the shared secrets.  They should be the same.
            //  Both sides now have a secret that only they know.
            //  ---------------------------------------------------------
            Console.WriteLine(sharedSecret1);
            Console.WriteLine(sharedSecret2);
        }