Exemplo n.º 1
0
        static void BackdoorSpeedTest(int e, int keyLen, int certainty, string pubKey)
        {
            byte[]     bytes = Encoding.ASCII.GetBytes(SAMPLE);
            BigInteger var   = new BigInteger(bytes);

            Console.WriteLine("[Backdoor] <Speed> test: keyLen = {0}", keyLen);

            DateTime   start      = DateTime.Now;
            Rsa        backdoored = RsaBackdoor.Inject(BigInteger.ValueOf(e), keyLen, certainty, StrToBytes(pubKey));
            BigInteger enc        = backdoored.Encrypt(var);

            var = backdoored.Decrypt(enc);
            TimeSpan timeSpan = DateTime.Now - start;

            Console.WriteLine("Time: {0}", timeSpan.TotalMilliseconds);
            GC.Collect();
        }
Exemplo n.º 2
0
        static bool BackdoorTest(int e, int keyLen, int certainty, string pubKey, string privKey)
        {
            Rsa backdoored = RsaBackdoor.Inject(BigInteger.ValueOf(e), keyLen, certainty, StrToBytes(pubKey));
            Rsa recovered  = RsaBackdoor.Extract(BigInteger.ValueOf(e), backdoored.Params.n, certainty, StrToBytes(privKey));

            byte[]     result, bytes = Encoding.ASCII.GetBytes(SAMPLE);
            BigInteger enc           = backdoored.Encrypt(new BigInteger(1, bytes));

            try
            {
                result = recovered.Decrypt(enc).ToByteArray();
            }
            catch (ArgumentOutOfRangeException)
            {
                return(false);
            }
            return(Encoding.ASCII.GetString(result) == SAMPLE);
        }