Exemple #1
0
        public static string GetDigitalSignature(out int N, out int E, out long D)
        {
            RSAEncryptDecrypt.GenerateKeys(out N, out E, out D);
            var Hesh = GetHesh(N);

            return(RSAEncryptDecrypt.Encrypt(E, N, Hesh));
        }
Exemple #2
0
        //--------------------------------
        //   Генерация ключей
        //--------------------------------
        public static void GenerateKeys(out int N, out int E, out long D)
        {
            var P         = 0;
            var Q         = 0;
            var ProstList = RSAEncryptDecrypt.ReshetoEratosfena(out P, out Q);

            N = P * Q;

            var M = (P - 1) * (Q - 1);

            E = 0;
            while (true)
            {
                var rnd = ProstList[new Random().Next(0, ProstList.Count - 1)];
                if (!EuclidIsNOD1(rnd, M))
                {
                    E = rnd;
                    break;
                }
            }

            D = 1;
            while (D * E % M != 1)
            {
                D++;
            }
        }
Exemple #3
0
        public static bool CheckDigitalSignature(int N, long D, string HeshE)
        {
            var Hesh  = RSAEncryptDecrypt.Decrypt(D, N, HeshE);
            var Hesh2 = GetHesh(N);

            if (Hesh == Hesh2)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }