コード例 #1
0
        public static void Dekriptimi(string message, bool opa)
        {
            string[] words = message.Split('.');
            var      bytes = Convert.FromBase64String(words[0]);
            string   user  = Encoding.UTF8.GetString(bytes);

            // Console.WriteLine(user);
            byte[] bytes1 = Convert.FromBase64String(words[1]);
            //string IV = Encoding.UTF8.GetString(bytes1);
            // Console.WriteLine(IV);
            // bytes1 = Formovargun(IV);
            string path = "C:\\Users\\Lenovo\\Desktop\\Detyra1_DS-Gr-6-master\\ds\\bin\\Debug\\netcoreapp3.0\\keys\\" + user + ".pem";

            //Console.WriteLine(path);

            if (!File.Exists(path))
            {
                string s = "Celesi " + user + " nuk ekziston";
                // Console.WriteLine("Celesi " + user + " nuk ekziston");
            }
            else
            {
                RSACryptoServiceProvider rsaPriv  = new RSACryptoServiceProvider();
                Chilkat.PrivateKey       privKey2 = new Chilkat.PrivateKey();
                privKey2.LoadPemFile(path);
                string privKeyXml = privKey2.GetXml();



                rsaPriv.FromXmlString(privKeyXml);
                byte[] dekodimi     = Convert.FromBase64String(words[2]);
                byte[] decryptedRSA = rsaPriv.Decrypt(dekodimi, false);
                byte[] dekodimiDes  = Convert.FromBase64String(words[3]);


                Console.WriteLine("Marresi: " + user);



                Console.WriteLine("Mesazhi: " + Encoding.UTF8.GetString(Desdekriptim(decryptedRSA, bytes1, dekodimiDes)));
                if (opa)
                {
                    byte[] dataToverify = Convert.FromBase64String(words[5]);
                    var    Bytes12      = Convert.FromBase64String(words[4]);
                    string perdoruesi   = Encoding.UTF8.GetString(Bytes12);
                    Console.WriteLine("Derguesi" + perdoruesi);
                    if (Sign.VerifySignedHash(dataToverify, Desdekriptim(decryptedRSA, bytes1, dekodimiDes), perdoruesi))
                    {
                        Console.WriteLine("Nenshkrami eshte valid");
                    }
                }
            }
        }
コード例 #2
0
        public static void exportKey(string type, string name, string path)
        {
            string path1 = "C:\\Users\\Lenovo\\Desktop\\Detyra1_DS-Gr-6-master\\ds\\bin\\Debug\\netcoreapp3.0\\keys\\" + name + ".pem";
            string path2 = "C:\\Users\\Lenovo\\Desktop\\Detyra1_DS-Gr-6-master\\ds\\bin\\Debug\\netcoreapp3.0\\keys\\" + name + ".pub.pem";

            if ((type == "private"))
            {
                if (!File.Exists(path1))
                {
                    Console.WriteLine("celesi nuk ekziston");
                }
                else if (path == "")
                {
                    //XElement file = XElement.Load(@path1);
                    Chilkat.PrivateKey pkey = new Chilkat.PrivateKey();
                    pkey.LoadPem(path1);
                    string pkeyXml;
                    // Get the private key in XML format:
                    pkeyXml = pkey.GetXml();
                    Console.WriteLine(pkeyXml);
                }
                else
                {
                    XElement file = XElement.Load(@path1);
                    //Console.WriteLine(file);
                    file.Save("keys1\\" + name + ".xml");
                    file.Save(path);
                    Console.WriteLine("celsi u ruajt ne folderin key1");
                }
            }
            else if (type == "public")
            {
                if (!File.Exists(path2))
                {
                    Console.WriteLine("celesi nuk ekziston");
                }
                else if (path == "")
                {
                    XElement file = XElement.Load(@path1);
                    Console.WriteLine(file);
                    //XElement file = XElement.Load(@path1);
                    Chilkat.PublicKey pukey = new Chilkat.PublicKey();
                    pukey.LoadOpenSslPemFile(path1);
                    string pkeyXml;
                    // Get the private key in XML format:
                    pkeyXml = pukey.GetXml();
                    Console.WriteLine(pkeyXml);
                }
                else
                {
                    XElement file = XElement.Load(@path1);
                    //Console.WriteLine(file);
                    file.Save("key1\\" + name + ".pub.xml");
                    file.Save(path);
                    Console.WriteLine("celsi u ruajt ne folderin key1");



                    //XmlDocument FILE = new XmlDocument();
                    //FILE.LoadXml(file);
                    //FILE.Save("C:\\keys1\\" + name + ".pub.xml");
                    //
                }
            }
            else
            {
                Console.WriteLine("Operacioni qe keni kerkuar nuk mund te mundesohet");
                shfaq();
            }
        }