Example #1
0
        public void InitKeys(int p, int q, int e)
        {
            if (AllFunctions.IsPrime(p))
            {
                _p = p;
            }
            else
            {
                throw new Exception("p isn't prime ");
            }
            if (AllFunctions.IsPrime(q))
            {
                _q = q;
            }
            else
            {
                throw new Exception("q isn't prime ");
            }
            _n  = AllFunctions.ComputeN(_p, _q);
            _fn = AllFunctions.ComputeFn(_p, _q);
            if (AllFunctions.IsCoprime(e, _fn))
            {
                _e = e;
            }
            else
            {
                throw new Exception("e isn't coprime ");
            }
            _d = AllFunctions.ComputeD(_fn, _e);

            PublicKey  = new KeyValuePair <int, int>(_e, _n);
            PrivateKey = new KeyValuePair <int, int>(_d, _n);
        }
Example #2
0
        private void InitKeys()
        {
            _p  = AllFunctions.GeneratePrimaryNum();
            _q  = AllFunctions.GeneratePrimaryNum();
            _n  = AllFunctions.ComputeN(_p, _q);
            _fn = AllFunctions.ComputeFn(_p, _q);
            _e  = AllFunctions.GenerateE(_fn);
            _d  = AllFunctions.ComputeD(_fn, _e);

            PublicKey  = new KeyValuePair <int, int>(_e, _n);
            PrivateKey = new KeyValuePair <int, int>(_d, _n);
        }