Пример #1
0
        // This method is responsible for generating public and private key if keys are not present in consul
        public static async System.Threading.Tasks.Task KeyGeneratorAsync(ConsulClient client)
        {
            Chilkat.Global glob = new Chilkat.Global();
            glob.UnlockBundle("Anything for 30-day trial");

            Chilkat.Rsa rsaKey = new Chilkat.Rsa();

            rsaKey.GenerateKey(1024);
            var rsaPrivKey         = rsaKey.ExportPrivateKeyObj();
            var rsaPrivKeyAsString = rsaKey.ExportPrivateKey();

            var rsaPublicKey         = rsaKey.ExportPublicKeyObj();
            var rsaPublicKeyAsString = rsaKey.ExportPublicKey();

            var putPair = new KVPair("myPublicKey")
            {
                Value = Encoding.UTF8.GetBytes(rsaPublicKeyAsString)
            };
            var putAttempt = await client.KV.Put(putPair);


            var putPair1 = new KVPair("myPrivateKey")
            {
                Value = Encoding.UTF8.GetBytes(rsaPrivKeyAsString)
            };
            var putAttempt1 = await client.KV.Put(putPair1);
        }
Пример #2
0
        public static void Createuser(string user)
        {
            Connectimimedb.InsertStudent(user);
            Chilkat.Global glob = new Chilkat.Global();
            Chilkat.Rsa    rsa  = new Chilkat.Rsa();
            glob.UnlockBundle("hELLOW");



            // Generate a 1024-bit key.  Chilkat RSA supports
            // key sizes ranging from 512 bits to 4096 bits.
            bool success = rsa.GenerateKey(1024);

            if (success != true)
            {
                Console.WriteLine(rsa.LastErrorText);
                return;
            }

            // Keys are exported in XML format:
            string publicKeyXml = rsa.ExportPublicKey();


            string privateKeyXml = rsa.ExportPrivateKey();


            // Save the private key in PEM format:
            Chilkat.PrivateKey privKey = new Chilkat.PrivateKey();
            success = privKey.LoadXml(privateKeyXml);
            success = privKey.SaveRsaPemFile("C:\\Users\\Lenovo\\Desktop\\Detyra1_DS-Gr-6-master\\ds\\bin\\Debug\\netcoreapp3.0\\keys\\" + user + ".pem");
            Console.WriteLine("Eshte krijuar qelesi privat " + "keys\\" + user + ".pem");
            // Save the public key in PEM format:
            Chilkat.PublicKey pubKey = new Chilkat.PublicKey();
            success = pubKey.LoadXml(publicKeyXml);
            success = pubKey.SaveOpenSslPemFile("C:\\Users\\Lenovo\\Desktop\\Detyra1_DS-Gr-6-master\\ds\\bin\\Debug\\netcoreapp3.0\\keys\\" + user + ".pub.pem");
            Console.WriteLine("Eshte krijuar qelesi public " + "keys\\" + user + ".pub.pem");
        }