Beispiel #1
0
        public virtual void testRSACrypt1024_BiggerBlock()
        {
            System.Console.Out.WriteLine("RSACrypt1024Bigger");
            int            keySize = 1024;
            CryptobyClient client  = new CryptobyClient();
            CryptobyCore   core    = new CryptobyCore(client);

            java.util.Random rand = new java.util.Random();
            for (int i = 1; i < 50; i++)
            {
                byte[] expResult = new byte[i * 100];
                rand.nextBytes(expResult);
                KeyGenRSA generator = new KeyGenRSA(core);
                generator.initGenerator(keySize);
                byte[]   publicKey  = generator.getPublicKeyByte();
                byte[]   privateKey = generator.getPrivateKeyByte();
                CryptRSA rsa        = new CryptRSA();
                byte[]   encres     = rsa.encrypt(expResult, publicKey);
                byte[]   encres2    = rsa.encrypt(expResult, publicKey);;
                byte[]   result     = rsa.decrypt(encres, privateKey);
                byte[]   result2    = rsa.decrypt(encres2, privateKey);
                Assert.AreEqual(result, result2);
                Assert.AreEqual(expResult, result);
            }
        }
Beispiel #2
0
        public virtual void testRSACrypt1024false()
        {
            System.Console.Out.WriteLine("RSACrypt1024false");
            int            keySize   = 1024;
            CryptobyClient client    = new CryptobyClient();
            CryptobyCore   core      = new CryptobyCore(client);
            KeyGenRSA      generator = new KeyGenRSA(core);

            generator.initGenerator(keySize);
            byte[] plainInput = Encoding.UTF8.GetBytes("Text to Test for Testing from Tester by Testcase"
                                                       );
            string publicKeyString = generator.getPublicKey();

            byte[] publicKey = CryptobyHelper.hexStringToBytes(publicKeyString);
            generator.initGenerator(keySize);
            string privateKeyString = generator.getPrivateKey();

            byte[]   privateKey = CryptobyHelper.hexStringToBytes(privateKeyString);
            CryptRSA rsa        = new CryptRSA();

            byte[] expResult = plainInput;
            byte[] result    = rsa.encrypt(plainInput, publicKey);
            result = rsa.decrypt(result, privateKey);
            NUnit.Framework.Assert.IsFalse(Arrays.equals(expResult, result));
        }
Beispiel #3
0
        public virtual void testRSACrypt1024_longString()
        {
            System.Console.Out.WriteLine("RSACrypt1024longString");
            int            keySize   = 1024;
            CryptobyClient client    = new CryptobyClient();
            CryptobyCore   core      = new CryptobyCore(client);
            KeyGenRSA      generator = new KeyGenRSA(core);

            generator.initGenerator(keySize);
            string longString = "Warmly little before cousin sussex entire men set. " + "Blessing it ladyship on sensible judgment settling outweigh. "
                                + "Worse linen an of civil jokes leave offer. Parties all clothes" + " removal cheered calling prudent her. And residence for met "
                                + "the estimable disposing. Mean if he they been no hold mr. Is " + "at much do made took held help. Latter person am secure of "
                                + "estate genius at.Six started far placing saw respect females " + "old. Civilly why how end viewing attempt related enquire visitor."
                                + " Man particular insensible celebrated conviction stimulated " + "principles day. Sure fail or in said west. Right my front it "
                                + "wound cause fully am sorry if. She jointure goodness interest " + "debating did outweigh. Is time from them full my gone in went."
                                + " Of no introduced am literature excellence mr stimulated " + "contrasted increasing. Age sold some full like rich new. "
                                + "Amounted repeated as believed in confined juvenile.Started his" + " hearted any civilly. So me by marianne admitted speaking. "
                                + "Men bred fine call ask. Cease one miles truth day above seven. " + "Suspicion sportsmen provision suffering mrs saw engrossed something. "
                                + "Snug soon he on plan in be dine some.";

            byte[]   plainInput = Encoding.UTF8.GetBytes(longString);
            byte[]   publicKey  = generator.getPublicKeyByte();
            byte[]   privateKey = generator.getPrivateKeyByte();
            CryptRSA rsa        = new CryptRSA();

            byte[] expResult = plainInput;
            byte[] enc       = rsa.encrypt(plainInput, publicKey);
            byte[] result    = rsa.decrypt(enc, privateKey);
            Assert.AreEqual(expResult, result);
        }
Beispiel #4
0
 public virtual void testRSACrypt1024_BiggerBlock()
 {
     System.Console.Out.WriteLine("RSACrypt1024Bigger");
     int keySize = 1024;
     CryptobyClient client = new CryptobyClient();
     CryptobyCore core = new CryptobyCore(client);
     java.util.Random rand = new java.util.Random();
     for(int i = 1;i<50;i++){
         byte[] expResult = new byte[i * 100];
         rand.nextBytes(expResult);
         KeyGenRSA generator = new KeyGenRSA(core);
         generator.initGenerator(keySize);
         byte[] publicKey = generator.getPublicKeyByte();
         byte[] privateKey = generator.getPrivateKeyByte();
         CryptRSA rsa = new CryptRSA();
         byte[] encres = rsa.encrypt (expResult, publicKey);
         byte[] encres2 = rsa.encrypt (expResult, publicKey);;
         byte[] result = rsa.decrypt(encres, privateKey);
         byte[] result2 = rsa.decrypt(encres2, privateKey);
         Assert.AreEqual(result, result2);
         Assert.AreEqual(expResult, result);
     }
 }
Beispiel #5
0
        public virtual void testRSACrypt1024_oneBlock()
        {
            System.Console.Out.WriteLine("RSACrypt1024oneBlock");
            int            keySize   = 1024;
            CryptobyClient client    = new CryptobyClient();
            CryptobyCore   core      = new CryptobyCore(client);
            KeyGenRSA      generator = new KeyGenRSA(core);

            generator.initGenerator(keySize);
            string smallString = "Text to Test for Testing from Tester by Testcase." + "Text to Test for Testing from Tester by Testcase.Text to Test";

            byte[]   plainInput = Encoding.UTF8.GetBytes(smallString);
            byte[]   publicKey  = generator.getPublicKeyByte();
            byte[]   privateKey = generator.getPrivateKeyByte();
            CryptRSA rsa        = new CryptRSA();

            byte[] expResult = plainInput;
            byte[] result    = rsa.encrypt(plainInput, publicKey);
            result = rsa.decrypt(result, privateKey);
            Assert.AreEqual(expResult, result);
        }
Beispiel #6
0
 public virtual void testRSACrypt1024false()
 {
     System.Console.Out.WriteLine("RSACrypt1024false");
     int keySize = 1024;
     CryptobyClient client = new CryptobyClient();
     CryptobyCore core = new CryptobyCore(client);
     KeyGenRSA generator = new KeyGenRSA(core);
     generator.initGenerator(keySize);
     byte[] plainInput = Encoding.UTF8.GetBytes("Text to Test for Testing from Tester by Testcase"
         );
     string publicKeyString = generator.getPublicKey();
     byte[] publicKey = CryptobyHelper.hexStringToBytes(publicKeyString);
     generator.initGenerator(keySize);
     string privateKeyString = generator.getPrivateKey();
     byte[] privateKey = CryptobyHelper.hexStringToBytes(privateKeyString);
     CryptRSA rsa = new CryptRSA();
     byte[] expResult = plainInput;
     byte[] result = rsa.encrypt(plainInput, publicKey);
     result = rsa.decrypt(result, privateKey);
     NUnit.Framework.Assert.IsFalse(Arrays.equals(expResult, result));
 }
        public virtual void testGetAndPutByteFiles()
        {
            System.Console.Out.WriteLine("Put Plaintext, get Plainfile, encrypt and decrypt Byte Files");
            for (int i = 1; i < 100; i += 3)
            {
                string filePathPlain = "test.txt";
                string filePathEnc = "test.cty";
                string filePathDec = "test2.txt";
                int keySize = 1024;
                byte[] testBytes = new byte[i * 100 + i];
                new Random().nextBytes(testBytes);
                CryptobyClient client = new CryptobyClient();
                CryptobyCore core = new CryptobyCore(client);
                CryptRSA rsa = new CryptRSA();
                KeyGenRSA generator = new KeyGenRSA(core);
                try
                {
                    CryptobyFileManager.putBytesToFile(filePathPlain, testBytes);
                }
                catch (IOException ex) {
                    Logger.getLogger (typeof(CryptobyFileManagerTest).FullName).log (Level.SEVERE, null
                        , ex);
                }
                generator.initGenerator(keySize);
                byte[] publicKey = generator.getPublicKeyByte();
                byte[] privateKey = generator.getPrivateKeyByte();
                byte[] plainInput = null;
                try
                {
                    plainInput = CryptobyFileManager.getBytesFromFile(filePathPlain);
                }
                catch (IOException ex)
                {
                    Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
                        , ex);
                }
                Assert.AreEqual(testBytes, plainInput);
                byte[] encrypt = rsa.encrypt(plainInput, publicKey);
                // Put encrypted Bytes from File
                try
                {
                    CryptobyFileManager.putBytesToFile(filePathEnc, encrypt);
                }
                catch (IOException ex)
                {
                    Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
                        , ex);
                }
                // Get encrypted Bytes from File
                byte[] fileEncrypt = null;
                try
                {
                    fileEncrypt = CryptobyFileManager.getBytesFromFile (filePathEnc);
                }
                catch (IOException ex)
                {
                    Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
                        , ex);
                }
                Assert.AreEqual(fileEncrypt, encrypt);

                byte[] decrypt = rsa.decrypt(fileEncrypt, privateKey);
                Assert.AreEqual(testBytes, decrypt);
                try
                {
                    CryptobyFileManager.putBytesToFile(filePathDec, decrypt);
                }
                catch (IOException ex)
                {
                    Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
                        , ex);
                }
            }
        }
Beispiel #8
0
 public void testRSADec()
 {
     resData = rsa.decrypt(modData, privKey);
 }
        public virtual void testGetAndPutByteFiles()
        {
            System.Console.Out.WriteLine("Put Plaintext, get Plainfile, encrypt and decrypt Byte Files");
            for (int i = 1; i < 100; i += 3)
            {
                string filePathPlain = "test.txt";
                string filePathEnc   = "test.cty";
                string filePathDec   = "test2.txt";
                int    keySize       = 1024;
                byte[] testBytes     = new byte[i * 100 + i];
                new Random().nextBytes(testBytes);
                CryptobyClient client    = new CryptobyClient();
                CryptobyCore   core      = new CryptobyCore(client);
                CryptRSA       rsa       = new CryptRSA();
                KeyGenRSA      generator = new KeyGenRSA(core);
                try
                {
                    CryptobyFileManager.putBytesToFile(filePathPlain, testBytes);
                }
                catch (IOException ex) {
                    Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
                                                                                   , ex);
                }
                generator.initGenerator(keySize);
                byte[] publicKey  = generator.getPublicKeyByte();
                byte[] privateKey = generator.getPrivateKeyByte();
                byte[] plainInput = null;
                try
                {
                    plainInput = CryptobyFileManager.getBytesFromFile(filePathPlain);
                }
                catch (IOException ex)
                {
                    Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
                                                                                   , ex);
                }
                Assert.AreEqual(testBytes, plainInput);
                byte[] encrypt = rsa.encrypt(plainInput, publicKey);
                // Put encrypted Bytes from File
                try
                {
                    CryptobyFileManager.putBytesToFile(filePathEnc, encrypt);
                }
                catch (IOException ex)
                {
                    Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
                                                                                   , ex);
                }
                // Get encrypted Bytes from File
                byte[] fileEncrypt = null;
                try
                {
                    fileEncrypt = CryptobyFileManager.getBytesFromFile(filePathEnc);
                }
                catch (IOException ex)
                {
                    Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
                                                                                   , ex);
                }
                Assert.AreEqual(fileEncrypt, encrypt);

                byte[] decrypt = rsa.decrypt(fileEncrypt, privateKey);
                Assert.AreEqual(testBytes, decrypt);
                try
                {
                    CryptobyFileManager.putBytesToFile(filePathDec, decrypt);
                }
                catch (IOException ex)
                {
                    Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
                                                                                   , ex);
                }
            }
        }
Beispiel #10
0
 public virtual void testRSACrypt1024_longString()
 {
     System.Console.Out.WriteLine("RSACrypt1024longString");
     int keySize = 1024;
     CryptobyClient client = new CryptobyClient();
     CryptobyCore core = new CryptobyCore(client);
     KeyGenRSA generator = new KeyGenRSA(core);
     generator.initGenerator(keySize);
     string longString = "Warmly little before cousin sussex entire men set. " + "Blessing it ladyship on sensible judgment settling outweigh. "
          + "Worse linen an of civil jokes leave offer. Parties all clothes" + " removal cheered calling prudent her. And residence for met "
          + "the estimable disposing. Mean if he they been no hold mr. Is " + "at much do made took held help. Latter person am secure of "
          + "estate genius at.Six started far placing saw respect females " + "old. Civilly why how end viewing attempt related enquire visitor."
          + " Man particular insensible celebrated conviction stimulated " + "principles day. Sure fail or in said west. Right my front it "
          + "wound cause fully am sorry if. She jointure goodness interest " + "debating did outweigh. Is time from them full my gone in went."
          + " Of no introduced am literature excellence mr stimulated " + "contrasted increasing. Age sold some full like rich new. "
          + "Amounted repeated as believed in confined juvenile.Started his" + " hearted any civilly. So me by marianne admitted speaking. "
          + "Men bred fine call ask. Cease one miles truth day above seven. " + "Suspicion sportsmen provision suffering mrs saw engrossed something. "
          + "Snug soon he on plan in be dine some.";
     byte[] plainInput = Encoding.UTF8.GetBytes(longString);
     byte[] publicKey = generator.getPublicKeyByte();
     byte[] privateKey = generator.getPrivateKeyByte();
     CryptRSA rsa = new CryptRSA();
     byte[] expResult = plainInput;
     byte[] enc = rsa.encrypt(plainInput, publicKey);
     byte[] result = rsa.decrypt(enc, privateKey);
     Assert.AreEqual(expResult, result);
 }
Beispiel #11
0
 public virtual void testRSACrypt1024_oneBlock()
 {
     System.Console.Out.WriteLine("RSACrypt1024oneBlock");
     int keySize = 1024;
     CryptobyClient client = new CryptobyClient();
     CryptobyCore core = new CryptobyCore(client);
     KeyGenRSA generator = new KeyGenRSA(core);
     generator.initGenerator(keySize);
     string smallString = "Text to Test for Testing from Tester by Testcase." + "Text to Test for Testing from Tester by Testcase.Text to Test";
     byte[] plainInput = Encoding.UTF8.GetBytes(smallString);
     byte[] publicKey = generator.getPublicKeyByte();
     byte[] privateKey = generator.getPrivateKeyByte();
     CryptRSA rsa = new CryptRSA();
     byte[] expResult = plainInput;
     byte[] result = rsa.encrypt(plainInput, publicKey);
     result = rsa.decrypt(result, privateKey);
     Assert.AreEqual(expResult, result);
 }