Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
 /// <summary>Constructor sets variables and initializes the SecureRandom object.</summary>
 /// <remarks>Constructor sets variables and initializes the SecureRandom object.</remarks>
 /// <param name="appCore">Input CryptobyCore object to get a primetest object</param>
 /// <param name="keyBitSize">
 /// With the half size of this key will generate be a prime
 /// number in the run method
 /// </param>
 public GenPrimeThread(CryptobyCore appCore, int keyBitSize)
 {
     scRandom       = new SecureRandom();
     halfKeyBitSize = keyBitSize / 2;
     keyByteSize    = halfKeyBitSize / 8;
     core           = appCore;
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 5
0
        [TestFixtureSetUp] public void Init()
        {
            CryptobyClient client = new CryptobyClient();
            CryptobyCore   core   = new CryptobyCore(client);

            keyGen = new KeyGenRSA(core);
        }
Exemplo n.º 6
0
 /// <summary>Constructor sets variables and initializes the SecureRandom object.</summary>
 /// <remarks>Constructor sets variables and initializes the SecureRandom object.</remarks>
 /// <param name="appCore">Input CryptobyCore object to get a primetest object</param>
 /// <param name="keyBitSize">
 /// With the half size of this key will generate be a prime
 /// number in the run method
 /// </param>
 public GenPrimeThread(CryptobyCore appCore, int keyBitSize)
 {
     scRandom = new SecureRandom();
     halfKeyBitSize = keyBitSize / 2;
     keyByteSize = halfKeyBitSize / 8;
     core = appCore;
 }
Exemplo n.º 7
0
 public void Init()
 {
     kb10 = 1024 * 10;
     kb50 = kb10 * 5;
     kb100 = kb10 * 10;
     client = new CryptobyClient();
     core = new CryptobyCore(client);
     keyGen = new KeyGenRSA(core);
     rsa = new CryptRSA();
 }
Exemplo n.º 8
0
 [TestFixtureSetUp] public void Init()
 {
     kb10   = 1024 * 10;
     kb50   = kb10 * 5;
     kb100  = kb10 * 10;
     client = new CryptobyClient();
     core   = new CryptobyCore(client);
     keyGen = new KeyGenRSA(core);
     rsa    = new CryptRSA();
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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));
 }
Exemplo n.º 11
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);
     }
 }
Exemplo n.º 12
0
 public void Init()
 {
     client = new CryptobyClient();
     core = new CryptobyCore(client);
     keyGen = new KeyGenRSA(core);
 }
        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);
                }
            }
        }
 public virtual void testPutAndGetKey()
 {
     System.Console.Out.WriteLine("Put and Get Keys");
     string publicKeyFilePath = "publicKey.pub";
     string privateKeyFilePath = "privateKey.prv";
     int keySize = 1024;
     CryptobyClient client = new CryptobyClient();
     CryptobyCore core = new CryptobyCore(client);
     KeyGenRSA generator = new KeyGenRSA(core);
     generator.initGenerator(keySize);
     byte[] publicKeyByte = generator.getPublicKeyByte();
     byte[] privateKeyByte = generator.getPrivateKeyByte();
     string publicKey = generator.getPublicKey();
     string privateKey = generator.getPrivateKey();
     try
     {
         CryptobyFileManager.putKeyToFile(publicKeyFilePath, publicKey);
     }
     catch (IOException ex)
     {
         Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
             , ex);
     }
     try
     {
         CryptobyFileManager.putKeyToFile(privateKeyFilePath, privateKey);
     }
     catch (IOException ex)
     {
         Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
             , ex);
     }
     byte[] resultPublic = null;
     try
     {
         resultPublic = CryptobyFileManager.getKeyFromFile(publicKeyFilePath);
     }
     catch (IOException ex)
     {
         Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
             , ex);
     }
     byte[] resultPrivate = null;
     try
     {
         resultPrivate = CryptobyFileManager.getKeyFromFile(privateKeyFilePath);
     }
     catch (IOException ex)
     {
         Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
             , ex);
     }
     Assert.AreEqual(publicKeyByte, resultPublic);
     Assert.AreEqual(privateKeyByte, resultPrivate);
     Assert.AreEqual(publicKey, CryptobyHelper.bytesToHexString(resultPublic
         ));
     Assert.AreEqual(privateKey, CryptobyHelper.bytesToHexString(resultPrivate
         ));
 }
Exemplo n.º 15
0
 /// <summary>Initial CryptobyCore object and available processor cores.</summary>
 /// <remarks>Initial CryptobyCore object and available processor cores.</remarks>
 /// <param name="appCore">Input CryptobyCore object which provides other objects of application.
 ///     </param>
 public KeyGenRSA(CryptobyCore appCore)
 {
     core  = appCore;
     cores = Runtime.getRuntime().availableProcessors();
 }
Exemplo n.º 16
0
 /// <param name="core"></param>
 public CryptobyConsole(CryptobyCore core)
 {
     this.core = core;
 }
Exemplo n.º 17
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);
 }
Exemplo n.º 18
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);
 }
        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);
                }
            }
        }
        public virtual void testPutAndGetKey()
        {
            System.Console.Out.WriteLine("Put and Get Keys");
            string         publicKeyFilePath  = "publicKey.pub";
            string         privateKeyFilePath = "privateKey.prv";
            int            keySize            = 1024;
            CryptobyClient client             = new CryptobyClient();
            CryptobyCore   core      = new CryptobyCore(client);
            KeyGenRSA      generator = new KeyGenRSA(core);

            generator.initGenerator(keySize);
            byte[] publicKeyByte  = generator.getPublicKeyByte();
            byte[] privateKeyByte = generator.getPrivateKeyByte();
            string publicKey      = generator.getPublicKey();
            string privateKey     = generator.getPrivateKey();

            try
            {
                CryptobyFileManager.putKeyToFile(publicKeyFilePath, publicKey);
            }
            catch (IOException ex)
            {
                Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
                                                                               , ex);
            }
            try
            {
                CryptobyFileManager.putKeyToFile(privateKeyFilePath, privateKey);
            }
            catch (IOException ex)
            {
                Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
                                                                               , ex);
            }
            byte[] resultPublic = null;
            try
            {
                resultPublic = CryptobyFileManager.getKeyFromFile(publicKeyFilePath);
            }
            catch (IOException ex)
            {
                Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
                                                                               , ex);
            }
            byte[] resultPrivate = null;
            try
            {
                resultPrivate = CryptobyFileManager.getKeyFromFile(privateKeyFilePath);
            }
            catch (IOException ex)
            {
                Logger.getLogger(typeof(CryptobyFileManagerTest).FullName).log(Level.SEVERE, null
                                                                               , ex);
            }
            Assert.AreEqual(publicKeyByte, resultPublic);
            Assert.AreEqual(privateKeyByte, resultPrivate);
            Assert.AreEqual(publicKey, CryptobyHelper.bytesToHexString(resultPublic
                                                                       ));
            Assert.AreEqual(privateKey, CryptobyHelper.bytesToHexString(resultPrivate
                                                                        ));
        }
Exemplo n.º 21
0
 /// <param name="core"></param>
 public CryptobyConsole(CryptobyCore core)
 {
     this.core = core;
 }
Exemplo n.º 22
0
		[TestFixtureSetUp] public void Init()
		{ 
			CryptobyClient client = new CryptobyClient();
			CryptobyCore core = new CryptobyCore(client);
			keyGen = new KeyGenRSA (core);
		}