示例#1
0
文件: Form1.cs 项目: 0leXis/RSA
        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));
        }
示例#2
0
文件: Form1.cs 项目: 0leXis/RSA
        //--------------------------------
        //   Генерация ключей
        //--------------------------------
        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++;
            }
        }
示例#3
0
文件: Form1.cs 项目: 0leXis/RSA
        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);
            }
        }