Exemple #1
0
        public void RSANumberDecryptionTest(int message, int privateKey, int commonKey, int encrypted)
        {
            // public key = -1, we won't need it for decryption!
            var rsaKey = new RivestShamirAdleman(privateKey, -1, commonKey);

            Assert.AreEqual(new BigInteger(message), rsaKey.Decrypt(encrypted));
        }
Exemple #2
0
        public void RSATest()
        {
            var rsaKey = new RivestShamirAdleman();

            TestContext.WriteLine(
                $"privateKey: {rsaKey.PrivateKey}, publicKey: {rsaKey.PublicKey}, commonKey: {rsaKey.CommonKey}");

            var encrypted = rsaKey.Encrypt("topSecret123");

            TestContext.WriteLine(encrypted);
            Assert.AreEqual("topSecret123", rsaKey.Decrypt(encrypted));
        }
Exemple #3
0
 // TODO Fix RSA algorithm for longer numbers
 // [TestCase(7)]
 // [TestCase(8)]
 // [TestCase(9)]
 // [TestCase(10)]
 // [TestCase(20)]
 // [TestCase(100)]
 public void RSAKeyPairGenerationTest(int messageLength)
 {
     for (var i = 0; i < 5; i++)
     {
         var rsaKey = new RivestShamirAdleman();
         for (var j = 0; j < 10; j++)
         {
             var number    = BigInteger.Parse(GenerateRandomNumberString(messageLength));
             var encrypted = rsaKey.Encrypt(number);
             var decrypted = rsaKey.Decrypt(encrypted);
             TestContext.WriteLine(
                 $"privateKey: {rsaKey.PrivateKey}, publicKey: {rsaKey.PublicKey}, commonKey: {rsaKey.CommonKey}");
             TestContext.WriteLine($"input: {number}, encrypted: {encrypted}, decrypted: {decrypted}");
             Assert.AreEqual(number, decrypted);
         }
     }
 }