Пример #1
0
        private static void TestEncription2()
        {
            var algo = new AsymmetricEncryptionService();

            var readerPrivate = new StreamReader("private-key-test.txt");
            var readerPublic  = new StreamReader("public-key-test.txt");

            var privateStr    = readerPrivate.ReadToEnd();
            var publicStrJson = readerPublic.ReadToEnd();

            var publicStr = JsonConvert.DeserializeObject <KeyJson>(publicStrJson).Key;

            var service = new SymmetricEncryptionService();
            var buf     = service.GenerateKey();

            var enc = algo.Encrypt(buf, publicStr);

            var str = Convert.ToBase64String(enc);

            Console.WriteLine(Convert.ToBase64String(buf));
            Console.WriteLine();
            Console.WriteLine(str);
            Console.WriteLine();

            enc = Convert.FromBase64String("ov0P6xO2AXxLJe7DgMmfjXjCPC488wAElzbTVy+N7/6Q4g0ld6iRnuXtI2FN06ym/loHSHH7sy9375xPoHy3bDp1jCcs1FrClnynlWUO5c2Xq5M1mQBYlcg3u5OG4wgttHtXa9/cftm1B9hl/Nh9ItSwKI/br61dlT+gebZzOO0=");

            algo = new AsymmetricEncryptionService();
            var res = algo.Decrypt(enc, privateStr);

            Console.WriteLine(Convert.ToBase64String(res));


            Console.ReadLine();
        }
Пример #2
0
        private static void TestEncriptionSync()
        {
            var algo = new SymmetricEncryptionService();

            var buf = Encoding.UTF8.GetBytes("Hello world!");

            var key   = algo.GenerateKey();
            var nonce = algo.GenerateNonce();

            var enc = algo.Encrypt(buf, key, nonce);

            Console.WriteLine("-------");
            Console.WriteLine($"key: {Convert.ToBase64String(key)}");
            Console.WriteLine($"nonce: {Convert.ToBase64String(nonce)}");
            Console.WriteLine("-------");
            Console.WriteLine(Convert.ToBase64String(enc));

            var res = algo.Decrypt(enc, key, nonce);

            Console.WriteLine("-------");
            Console.WriteLine(Encoding.UTF8.GetString(res));


            Console.WriteLine();
            Console.WriteLine("=-=-=-=-=-=-=-=-=-=-=-=");
            Console.WriteLine();
            var d1 = "wqi+neXmkFks+eUpnfsV8bygfNnVxSZSQ7tQaQk7i1AfXJxCTwyh8/HibqVd8AhN/B6GLfgUzN5MyHuLjpQR8Dl3lW6w9MownocjTUKdzF9C0QtVBD1DHNOjHyicnMmLPne9mhDhmbJul5N7DHXGd+SHySkvn1MpvnSSJbP1/HT0DiVID2U9kQkuVdhbUvj2+TweGw4fP0OE4oQAPtazyB2SKn+fNiXf0SmcS9c5ngRazsKi+WDFIXOJUK3B26LigLlZadjBSW0sdjY0ExRIMC6+I0Dc0iBaEzPjG12iwKDKeqmT/RLvsoZCWx3x1aHYIs8zOhLz9GmH3ZktboXKuSA3nrjOig+6oMj8lF62MmNZRUxEHAilu6wj75Q7kE0zFWJCTMaiXS/nSw/58k2yDhgXA1ksbHQxJfhkqmNlM3hLiIAT50tt94UL6tOcWq8iK/ymb7xhyhv9VhobEkQbhhdmcJxm8mBDZXjsUEYaO0ntYLhAbBmkUwwlhnNfFEtVn9FK9PgpBzgZuYTHX1DZZ4MATvNqxUdR4sbPupHFPXGU9xZFz+K+U2SETbKYkR0fmfJKsVNd5QcoF9yrtDOdvUVhZaY6d68j6D69K5m6J9ePcWlL9xYyZnqwMkYhTV13vDcGA8eYF5IIgLCp2tLwwY4Q7I4POIMmhmgapVSk1PY/kA85Fd8KGUjAgcfdMkJrpqJ5194HuMP7rqFld8aOUqSBhLVs53V0TIpxtvdSCvfBq3Lum1+IrKiI4y+KGr4mPm9/Or2JsWLP6FQtAIo+BGp5qdmxyNs1n9a9P9MIQr6Nv8OryKM0flnEnb9DM9j/Lt93aoPzDQO4YpfImI2pfZUcI19IyNV+cfK/RyKFY0v8nXJiCCGRLS/H28ZfVpKtMqnRfQiVzvDzJPLeKiIF3fHfjdV9+u6R+ShnHEThjbXwns3Zw/38XQYsmhuSG4NB2Q9dULzZfZDA";

            key   = Convert.FromBase64String("K7UOsz6j/sz/Sn/JJEQlJdyWzRUbnb9RlpG8umdXHDs=");
            nonce = Convert.FromBase64String("W5pOlo5BUNcc6lqpwynW8Q==");

            var d3 = Convert.FromBase64String(d1);

            res = algo.Decrypt(d3, key, nonce);
            Console.WriteLine(Encoding.UTF8.GetString(res));
        }