public void AdditionalTests(Byte[] data, RSAEncryptionPadding padding) { var customAsymProvider = new MyRSA(); // Should raise on derived asymmetric classes customAsymProvider.Encrypt(data, padding); // Noncompliant customAsymProvider.EncryptValue(data); // Noncompliant customAsymProvider.Decrypt(data, padding); // Noncompliant customAsymProvider.DecryptValue(data); // Noncompliant // Should raise on the Try* methods added in NET Core 2.1 // Note: this test is cheating - we can't currently referencing the // real 2.1 assemblies since the test project is targetting an older // NET Framework, so we're testing against a custom subclass // to which we've added the new method names. customAsymProvider.TryEncrypt(); // Noncompliant customAsymProvider.TryEncrypt(null); // Noncompliant customAsymProvider.TryDecrypt(); // Noncompliant customAsymProvider.TryDecrypt(null); // Noncompliant customAsymProvider.OtherMethod(); // Should raise on derived symmetric classes var customSymProvider = new MySymmetricCrypto(); customSymProvider.CreateEncryptor(); // Noncompliant customSymProvider.CreateDecryptor(); // Noncompliant }
public void ShouldEncryptAndDecryptEmptyArray() { MyRSA myRsa = new MyRSA(512); byte[] toEncrypt = { }; byte[] encrypted = myRsa.Encrypt(toEncrypt); Assert.AreEqual(0, encrypted.Length); byte[] decrypted = myRsa.Decrypt(encrypted); Assert.AreEqual(toEncrypt, decrypted); }
public void ShouldEncryptAndDecryptMultipleZerosToOneZero() { MyRSA myRsa = new MyRSA(512); byte[] toEncrypt = { 0, 0, 0 }; byte[] encrypted = myRsa.Encrypt(toEncrypt); Assert.AreEqual(64, encrypted.Length); byte[] decrypted = myRsa.Decrypt(encrypted); Assert.AreEqual(1, decrypted.Length); Assert.AreEqual(new byte[] { 0 }, decrypted); }
public void ShouldEncryptAndDecrypt1() { MyRSA myRsa = new MyRSA(512); byte[] toEncrypt = { 1 }; byte[] encrypted = myRsa.Encrypt(toEncrypt); Assert.AreEqual(64, encrypted.Length); Assert.AreEqual(1, encrypted[0]); byte[] decrypted = myRsa.Decrypt(encrypted); Assert.AreEqual(toEncrypt, decrypted); }
public void ShouldEncryptAndDecrypt100SetsOfRandomData() { int keyLength = 1024; // 1024 bit key for max data length of 64 bytes MyRSA myRsa = new MyRSA(keyLength); Random random = new Random(); for (int i = 0; i < 100; i++) { byte[] toEncrypt = new byte[random.Next(1, keyLength / (8 * 2))]; random.NextBytes(toEncrypt); toEncrypt[toEncrypt.Length - 1] |= (byte)random.Next(1, 255); // Prevent leading zeros byte[] encrypted = myRsa.Encrypt(toEncrypt); Assert.AreEqual(keyLength / 8, encrypted.Length); byte[] decrypted = myRsa.Decrypt(encrypted); Assert.AreEqual(toEncrypt, decrypted); } }
private void Debug() { //TaskTimer t = new TaskTimer(); //t.Execute(); string s = "MJ/0ee36iULGGDZC1e0NUv874aVVtVdD1be+4ryKkckKoqRgoiE/MZCWrM9aM7LvrBFWprwDYQvYTaH50rJWJTTi7adhB09UDHHK47BDyInWRFxQVZeO+99SvPcObgpTvYv6dkdRcrXkYoKTCz5y20++iLiScdHgMi4dg5pufCg="; string rst = MyRSA.Decrypt(s); string r = rst.Trim('\0'); LogHelper.Log(r); //BarCodePrinter barCodePrinter = new BarCodePrinter(); //barCodePrinter.Print("111","","",""); //var d = localData.GetBoxLockNoByTypeID(1); //idValidDevice.Init(); //idValidDevice.OnIDRead += new Action<string>(idValidDevice_OnIDRead); //elcWeight.Init(); //elcWeight.OnReadWeight += new Action<float>(elcWeight_OnReadWeight); //elcWeight.StartRead(); // BarCodePrinter printer = new BarCodePrinter(); //printer.Init(); //var a = service.userRegist("中文测试", "150125198501093611", "17011111111", "111111", "899413"); }