/// <summary>
 /// Initializes a new instance of <see cref="SymmetricEncryptionConfiguration"/> with default settings consisting of:
 /// <see cref="SymmetricAlgorithmType.Aes"/> encryption using <see cref="System.Security.Cryptography.CipherMode.CBC"/> and <see cref="System.Security.Cryptography.PaddingMode.PKCS7"/>.
 /// Plaintext strings are encoded using a UTF8 transform.
 /// All other strings (ciphertext, key, and IV strings) are encoded using a hex transform.
 /// </summary>
 public SymmetricEncryptionConfiguration()
 {
     AlgorithmType       = SymmetricAlgorithmType.Aes;
     CipherMode          = CipherMode.CBC;
     PaddingMode         = PaddingMode.PKCS7;
     PlainTextTransform  = StringTransform.FromEncoding(Encoding.UTF8);
     CipherTextTransform = StringTransform.GetHexTransform();
     KeyTransform        = StringTransform.GetHexTransform();
     IvTransform         = StringTransform.GetHexTransform();
 }
Beispiel #2
0
        public void NoEncryptionTest()
        {
            var encryption = new SymmetricEncryptionService(
                new SymmetricEncryptionConfiguration
            {
                AlgorithmType       = SymmetricAlgorithmType.None,
                PlainTextTransform  = StringTransform.FromEncoding(Encoding.UTF8),
                CipherTextTransform = StringTransform.FromEncoding(Encoding.UTF8)
            }
                );

            const string inputString  = InputStringTest;
            var          outputString = encryption.EncryptString(inputString, (string)null, null);

            Assert.AreEqual(inputString, outputString, "Encrypted string was not equal to the input string.");
        }
Beispiel #3
0
        public void NoEncryptionTransformTest()
        {
            var encryption = new SymmetricEncryptionService(
                new SymmetricEncryptionConfiguration
            {
                AlgorithmType       = SymmetricAlgorithmType.None,
                PlainTextTransform  = StringTransform.FromEncoding(Encoding.UTF8),
                CipherTextTransform = StringTransform.GetBase64Transform()
            }
                );

            const string inputString      = InputStringTest;
            var          encryptionOutput = encryption.EncryptString(inputString, (string)null, null);
            var          base64String     = Convert.ToBase64String(Encoding.UTF8.GetBytes(inputString));

            Assert.AreEqual(base64String, encryptionOutput, "Encrypted string was not equal to the base64 hash of the input string.");
        }
        public MainForm()
        {
            InitializeComponent();

            cboPlainTextStringTransformType.Items.Clear();
            cboCipherTextStringTransformType.Items.Clear();

            // List of supported transforms
            var stringTransformTypes = new[]
            {
                new StringTransformComboBoxItem("Default Encoding", StringTransform.FromEncoding(Encoding.Default)),
                new StringTransformComboBoxItem("Base64", StringTransform.GetBase64Transform()),
                new StringTransformComboBoxItem("Hex", StringTransform.GetHexTransform())
            };

            // Each combo box gets its own copy of the transform list
            cboPlainTextStringTransformType.DataSource  = new List <StringTransformComboBoxItem>(stringTransformTypes);
            cboCipherTextStringTransformType.DataSource = new List <StringTransformComboBoxItem>(stringTransformTypes);

            // Make sure we always select our first item
            cboPlainTextStringTransformType.SelectedIndex  = 0;
            cboCipherTextStringTransformType.SelectedIndex = 0;
        }
 private SymmetricEncryptionService CreateEncryptionService2()
 {
     return(new SymmetricEncryptionService(
                new SymmetricEncryptionConfiguration
     {
         AlgorithmType = GetAlgorithmType(),
         CipherMode = GetCipherMode(),
         PaddingMode = GetPaddingMode(),
         PlainTextTransform = cboPlainTextStringTransformType.SelectedValue as IStringTransform,
         CipherTextTransform = cboCipherTextStringTransformType.SelectedValue as IStringTransform,
         IvTransform = chkIvIsHex.Checked ? StringTransform.GetHexTransform() : StringTransform.FromEncoding(Encoding.Default),
         KeyTransform = chkKeyIsHex.Checked ? StringTransform.GetHexTransform() : StringTransform.FromEncoding(Encoding.Default)
     }
                ));
 }