Ejemplo n.º 1
0
        public void SecureData_Asymmetric()
        {
            string privateKey = AsymmetricCrypto.CreatePrivateKey(CryptoAlgorithm.RSA, 1024);
            string publicKey  = AsymmetricCrypto.GetPublicKey(CryptoAlgorithm.RSA, privateKey);

            byte[] plainText;
            byte[] cipherText;

            plainText  = new byte[] { 0, 1, 2, 3 };
            cipherText = SecureData.Encrypt(publicKey, plainText, CryptoAlgorithm.AES, 256);
            CollectionAssert.AreNotEqual(plainText, cipherText);
            CollectionAssert.AreEqual(plainText, SecureData.Decrypt(privateKey, cipherText));

            plainText  = new byte[] { 0, 1, 2, 3 };
            cipherText = SecureData.Encrypt(publicKey, plainText, CryptoAlgorithm.AES, 256, 1000);
            Assert.IsTrue(cipherText.Length >= 1000);

            plainText  = new byte[0];
            cipherText = SecureData.Encrypt(publicKey, plainText, CryptoAlgorithm.AES, 256);
            CollectionAssert.AreNotEqual(plainText, cipherText);
            CollectionAssert.AreEqual(plainText, SecureData.Decrypt(privateKey, cipherText));

            plainText = new byte[2000000];
            for (int i = 0; i < plainText.Length; i++)
            {
                plainText[i] = (byte)i;
            }

            cipherText = SecureData.Encrypt(publicKey, plainText, CryptoAlgorithm.AES, 256);
            CollectionAssert.AreNotEqual(plainText, cipherText);
            CollectionAssert.AreEqual(plainText, SecureData.Decrypt(privateKey, cipherText));
        }
Ejemplo n.º 2
0
        private void SaveSettings(BuildList storedBuilds)
        {
            Settings.Default.Domain            = TextBoxDomain.Text;
            Settings.Default.Port              = string.IsNullOrEmpty(TextBoxPort.Text) ? 80 : Convert.ToInt32(TextBoxPort.Text);
            Settings.Default.UserName          = TextBoxUserName.Text;
            Settings.Default.Password          = SecureData.Encrypt(PasswordBoxPassword.Password);
            Settings.Default.RefreshInterval   = Convert.ToInt32(ComboBoxRefreshInterval.Text);
            Settings.Default.UseSsl            = Convert.ToBoolean(RadioButtonProtocolHttps.IsChecked);
            Settings.Default.Builds            = storedBuilds;
            Settings.Default.HideInactive      = Convert.ToBoolean(CheckBoxHideInactive.IsChecked);
            Settings.Default.HideInactiveWeeks = Convert.ToInt32(ComboBoxHideInactive.Text);
            Settings.Default.ClientType        = (ClientType)Enum.Parse(typeof(ClientType), ComboBoxCIType.Text);
            Settings.Default.NumberOfColumns   = Convert.ToInt32(ComboBoxColumnsNumber.Text);

            Settings.Default.Save();
        }
Ejemplo n.º 3
0
        public void SecureData_Symmetric()
        {
            string       privateKey = AsymmetricCrypto.CreatePrivateKey(CryptoAlgorithm.RSA, 1024);
            string       publicKey  = AsymmetricCrypto.GetPublicKey(CryptoAlgorithm.RSA, privateKey);
            SymmetricKey argsEncrypt;
            SymmetricKey argsDecrypt;

            byte[] asymPlain;
            byte[] asymCipher;
            byte[] symPlain;
            byte[] symCipher;

            asymPlain  = new byte[] { 0, 1, 2, 3 };
            asymCipher = SecureData.Encrypt(publicKey, asymPlain, CryptoAlgorithm.AES, 256, 1000, out argsEncrypt);
            CollectionAssert.AreEqual(asymPlain, SecureData.Decrypt(privateKey, asymCipher, out argsDecrypt));

            symPlain  = new byte[] { 10, 20, 30, 40 };
            symCipher = SecureData.Encrypt(argsEncrypt, symPlain, 100);
            Assert.IsTrue(symCipher.Length >= 100);
            CollectionAssert.AreEqual(symPlain, SecureData.Decrypt(argsDecrypt, symCipher));
        }
Ejemplo n.º 4
0
        public void Decrypt_EncryptedString_ShouldMatchExpectedString()
        {
            string encryptedString = SecureData.Encrypt("Password");

            SecureData.Decrypt(encryptedString).ShouldBeEqual("Password");
        }
Ejemplo n.º 5
0
 public void Encrypt_DecryptedDataIsNull_ShouldThrowArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => SecureData.Encrypt(null));
 }