public void testRun(){ const int rounds = 3; Console.WriteLine ("Test Performance AES Data Enc/Dec"); Console.WriteLine ("Rounds: " + rounds); Console.WriteLine ("Cycles per Round: " + cycles); KeyGenSHA3 keyGen = new KeyGenSHA3(); privKey = keyGen.generateKeyByte(keySize, "password"); preData = new byte[mb1]; Console.WriteLine ("\nEncrypt AES 256 Bit 1MB"); PerfMeter.run(new Action(testAESEnc),rounds); Console.WriteLine ("\nDecrypt AES 256 Bit 1MB"); PerfMeter.run(new Action(testAESDec),rounds); Assert.AreEqual (preData,resData); preData = new byte[mb5]; Console.WriteLine ("\nEncrypt AES 256 Bit 5MB"); PerfMeter.run(new Action(testAESEnc),rounds); Console.WriteLine ("\nDecrypt AES 256 Bit 5MB"); PerfMeter.run(new Action(testAESDec),rounds); Assert.AreEqual (preData,resData); preData = new byte[mb10]; Console.WriteLine ("\nEncrypt AES 256 Bit 10MB"); PerfMeter.run(new Action(testAESEnc),rounds); Console.WriteLine ("\nDecrypt AES 256 Bit 10MB"); PerfMeter.run(new Action(testAESDec),rounds); Assert.AreEqual (preData,resData); }
public void testRun() { const int rounds = 3; Console.WriteLine ("Test Performance AES Data Enc/Dec"); Console.WriteLine ("Rounds: " + rounds); Console.WriteLine ("Cycles per Round: " + cycles); KeyGenSHA3 keyGen = new KeyGenSHA3(); privKey = keyGen.generateKeyByte(keySize, "password"); preData = new byte[mb1]; Console.WriteLine ("\nEncrypt AES 256 Bit 1MB"); PerfMeter.run(new Action(testAESEnc),rounds); Console.WriteLine ("\nDecrypt AES 256 Bit 1MB"); PerfMeter.run(new Action(testAESDec),rounds); Assert.AreEqual (preData,resData); preData = new byte[mb5]; Console.WriteLine ("\nEncrypt AES 256 Bit 5MB"); PerfMeter.run(new Action(testAESEnc),rounds); Console.WriteLine ("\nDecrypt AES 256 Bit 5MB"); PerfMeter.run(new Action(testAESDec),rounds); Assert.AreEqual (preData,resData); preData = new byte[mb10]; Console.WriteLine ("\nEncrypt AES 256 Bit 10MB"); PerfMeter.run(new Action(testAESEnc),rounds); Console.WriteLine ("\nDecrypt AES 256 Bit 10MB"); PerfMeter.run(new Action(testAESDec),rounds); Assert.AreEqual (preData,resData); }
/// <summary>Generate a SHA3 Hash/Key depend on password input as byte array.</summary> /// <remarks>Generate a SHA3 Hash/Key depend on password input as byte array.</remarks> /// <param name="keySize">Size of hash. Allowed are 224, 256, 384 and 512.</param> /// <param name="password">String password which will be hashed</param> /// <returns>SHA3 hash as byte array</returns> public virtual byte[] generateKeyByte(int keySize, string password) { byte[] bytePW = Encoding.UTF8.GetBytes(password); KeyGenSHA3.init(keySize); KeyGenSHA3.update(bytePW, bytePW.Length * 8); byte[] output = KeyGenSHA3.getHash(); return(output); }
/// <summary>Generate a SHA3 Hash/Key depend on password input as String.</summary> /// <remarks>Generate a SHA3 Hash/Key depend on password input as String.</remarks> /// <param name="keySize">Size of hash. Allowed are 224, 256, 384 and 512.</param> /// <param name="password">String password which will be hashed</param> /// <returns>SHA3 hash as Hex String</returns> public virtual string generateKey(int keySize, string password) { byte[] bytePW = Encoding.UTF8.GetBytes(password); KeyGenSHA3.init(keySize); KeyGenSHA3.update(bytePW, bytePW.Length * 8); string output = CryptobyHelper.bytesToHexString(KeyGenSHA3.getHash()); return(output); }
/// <summary>Generate a random SHA3 Hash/Key as byte array.</summary> /// <remarks>Generate a random SHA3 Hash/Key as byte array.</remarks> /// <param name="keySize">Size of hash. Allowed are 224, 256, 384 and 512.</param> /// <returns>SHA3 hash as byte array</returns> public virtual byte[] generateKeyByte(int keySize) { SecureRandom scRandom = new SecureRandom(); byte[] randomPW = new byte[40]; scRandom.nextBytes(randomPW); KeyGenSHA3.init(keySize); KeyGenSHA3.update(randomPW, randomPW.Length * 8); byte[] output = KeyGenSHA3.getHash(); return(output); }
public virtual void testGenerateKey_int_random_length512() { System.Console.Out.WriteLine("generate random 512bit Key"); int keySize = 512; KeyGenSHA3 instance = new KeyGenSHA3(); int expResult = 512; int result = Encoding.UTF8.GetBytes(instance.generateKey(keySize)).Length * 4; System.Console.Out.WriteLine(result); NUnit.Framework.Assert.AreEqual(expResult, result); }
public virtual void testGenerateKey_int_String() { System.Console.Out.WriteLine("generate 256bit Key and comparse with given Key"); int keySize = 256; string password = "******"; KeyGenSHA3 instance = new KeyGenSHA3(); string expResult = "e195622d04525e14469076f4175b990a72995ea7c9f379c465670c330b4f8b60"; string result = instance.generateKey(keySize, password); System.Console.Out.WriteLine(result); NUnit.Framework.Assert.AreEqual(expResult, result); }
/// <summary>Generate a random SHA3 Hash/Key as String.</summary> /// <remarks>Generate a random SHA3 Hash/Key as String.</remarks> /// <param name="keySize">Size of hash. Allowed are 224, 256, 384 and 512.</param> /// <returns>SHA3 hash as Hex String</returns> public virtual string generateKey(int keySize) { SecureRandom scRandom = new SecureRandom(); byte[] randomPW = new byte[40]; scRandom.nextBytes(randomPW); KeyGenSHA3.init(keySize); KeyGenSHA3.update(randomPW, randomPW.Length * 8); string output = CryptobyHelper.bytesToHexString(KeyGenSHA3.getHash()); return(output); }
public virtual void testEncryptDecrypt256() { System.Console.Out.WriteLine("encrypt and decrypt testphrase"); byte[] plainInput = Encoding.UTF8.GetBytes("Text to Test for Testing from Tester by Testcase" ); KeyGenSHA3 keyGen = new KeyGenSHA3(); string hexKey = keyGen.generateKey(256, "password"); byte[] bKey = CryptobyHelper.hexStringToBytes(hexKey); CryptAES instance = new CryptAES(); byte[] expResult = plainInput; byte[] result = instance.encrypt(plainInput, bKey); result = instance.decrypt(result, bKey); Assert.AreEqual(expResult, result); }
public virtual void testEncryptDecrypt256_HugeData() { System.Console.Out.WriteLine("encrypt and decrypt huge Data"); byte[] plainInput = new byte[1000000]; KeyGenSHA3 keyGen = new KeyGenSHA3(); string hexKey = keyGen.generateKey(256, "password"); byte[] bKey = CryptobyHelper.hexStringToBytes(hexKey); CryptAES instance = new CryptAES(); byte[] expResult = plainInput; byte[] result = instance.encrypt(plainInput, bKey); result = instance.decrypt(result, bKey); for (int i = 0; i < 10; i++) { result = instance.encrypt(plainInput, bKey); result = instance.decrypt(result, bKey); } Assert.AreEqual(expResult, result); }
public virtual void testEncryptDecrypt256_CBC() { System.Console.Out.WriteLine("encrypt and decrypt recurring words"); byte[] plainInput = Encoding.UTF8.GetBytes("TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest" ); KeyGenSHA3 keyGen = new KeyGenSHA3(); string hexKey = keyGen.generateKey(256, "password"); byte[] bKey = CryptobyHelper.hexStringToBytes(hexKey); CryptAES instance = new CryptAES(); byte[] expResult = plainInput; byte[] result = instance.encrypt(plainInput, bKey); string resString = CryptobyHelper.bytesToHexStringUpper(result); for (int i = 0; i < resString.Length - 32; i += 32) { Assert.IsFalse(resString.Substring(i, 32).Equals (resString.Substring(i + 32, 32))); } result = instance.decrypt(result, bKey); Assert.AreEqual(expResult, result); }
public void Init() { keyGen = new KeyGenSHA3 (); }
[TestFixtureSetUp] public void Init() { keyGen = new KeyGenSHA3(); }
public virtual void testEncryptDecrypt256_HugeData() { System.Console.Out.WriteLine("encrypt and decrypt huge Data"); byte[] plainInput = new byte[1000000]; KeyGenSHA3 keyGen = new KeyGenSHA3(); string hexKey = keyGen.generateKey(256, "password"); byte[] bKey = CryptobyHelper.hexStringToBytes(hexKey); CryptAES instance = new CryptAES(); byte[] expResult = plainInput; byte[] result = instance.encrypt(plainInput, bKey); result = instance.decrypt(result, bKey); for (int i = 0; i < 10;i++){ result = instance.encrypt(plainInput, bKey); result = instance.decrypt(result, bKey); } Assert.AreEqual(expResult, result); }