public static string Encryption_AES()
        {
            string StringToEncrypt = RandomString(16);

            // Registry...
            string keyName    = @"HKEY_CURRENT_USER";
            string subKey     = @"AESEncrytion";
            string valueName  = "AESKeyData";
            string valueName2 = "AppPassword";

            System.Security.Cryptography.DataProtectionScope dpScope = DataProtectionScope.CurrentUser;

            string key;
            int    keysize = 128;

            // Create Encryption Key.
            key = TTC1.GenerateKey(keysize);

            // For additional security Pin the key.
            GCHandle gch = GCHandle.Alloc(key, GCHandleType.Pinned);

            // Store key into registry, using DPAPI.
            TTC1.StoreKey(keyName, subKey, valueName, key, dpScope);

            // Encrypt the string.
            string EncryptedHexString = TTC1.Encrypt(StringToEncrypt, key, keysize);

            TTC1.StoreKey(keyName, subKey, valueName2, EncryptedHexString, dpScope);

            // Decrypt the string.
            string DecryptedHexString = TTC1.Decrypt(EncryptedHexString, TTC1.ReadKey(keyName, subKey, valueName), keysize);

            //Console.WriteLine("{0}", DecryptedHexString);

            return(DecryptedHexString);
        }
 private void InitializeComponent()
 {
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TTC1));
     this.label1       = new System.Windows.Forms.Label();
     this.label2       = new System.Windows.Forms.Label();
     this.textBox2     = new System.Windows.Forms.TextBox();
     this.label3       = new System.Windows.Forms.Label();
     this.richTextBox1 = new System.Windows.Forms.RichTextBox();
     this.button1      = new System.Windows.Forms.Button();
     this.textBox1     = new System.Windows.Forms.TextBox();
     this.SuspendLayout();
     //
     // label1
     //
     this.label1.AutoSize  = true;
     this.label1.BackColor = System.Drawing.SystemColors.ActiveBorder;
     this.label1.Font      = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.label1.Location  = new System.Drawing.Point(12, 25);
     this.label1.Name      = "label1";
     this.label1.Size      = new System.Drawing.Size(108, 25);
     this.label1.TabIndex  = 0;
     this.label1.Text      = "Username:"******"Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.label2.Location  = new System.Drawing.Point(12, 67);
     this.label2.Name      = "label2";
     this.label2.Size      = new System.Drawing.Size(104, 25);
     this.label2.TabIndex  = 1;
     this.label2.Text      = "Password:"******"Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.textBox2.Location              = new System.Drawing.Point(122, 67);
     this.textBox2.Name                  = "textBox2";
     this.textBox2.ReadOnly              = true;
     this.textBox2.Size                  = new System.Drawing.Size(202, 23);
     this.textBox2.TabIndex              = 3;
     this.textBox2.Text                  = TTC1.Encryption_AES();
     this.textBox2.UseSystemPasswordChar = true;
     //
     // label3
     //
     this.label3.AutoSize   = true;
     this.label3.BackColor  = System.Drawing.SystemColors.ActiveBorder;
     this.label3.Font       = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.label3.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
     this.label3.Location   = new System.Drawing.Point(126, 25);
     this.label3.Name       = "label3";
     this.label3.Size       = new System.Drawing.Size(76, 25);
     this.label3.TabIndex   = 4;
     this.label3.Text       = "iamr00t";
     //
     // richTextBox1
     //
     this.richTextBox1.BackColor = System.Drawing.SystemColors.ActiveCaption;
     this.richTextBox1.Location  = new System.Drawing.Point(384, 134);
     this.richTextBox1.Name      = "richTextBox1";
     this.richTextBox1.ReadOnly  = true;
     this.richTextBox1.Size      = new System.Drawing.Size(191, 43);
     this.richTextBox1.TabIndex  = 5;
     this.richTextBox1.Text      = "It\'s somewhere in the registry and only you can decrypt it!";
     //
     // button1
     //
     this.button1.Location = new System.Drawing.Point(316, 407);
     this.button1.Name     = "button1";
     this.button1.Size     = new System.Drawing.Size(172, 31);
     this.button1.TabIndex = 6;
     this.button1.Text     = "Login";
     this.button1.UseVisualStyleBackColor = true;
     this.button1.Click += new System.EventHandler(this.button1_Click);
     //
     // textBox1
     //
     this.textBox1.BackColor = System.Drawing.SystemColors.ActiveBorder;
     this.textBox1.Location  = new System.Drawing.Point(235, 367);
     this.textBox1.Name      = "textBox1";
     this.textBox1.Size      = new System.Drawing.Size(384, 22);
     this.textBox1.TabIndex  = 8;
     this.textBox1.Text      = "Enter the password";
     //
     // TTC1
     //
     this.AutoScaleDimensions   = new System.Drawing.SizeF(8F, 16F);
     this.AutoScaleMode         = System.Windows.Forms.AutoScaleMode.Font;
     this.BackgroundImage       = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
     this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
     this.ClientSize            = new System.Drawing.Size(800, 450);
     this.Controls.Add(this.textBox1);
     this.Controls.Add(this.button1);
     this.Controls.Add(this.richTextBox1);
     this.Controls.Add(this.label3);
     this.Controls.Add(this.textBox2);
     this.Controls.Add(this.label2);
     this.Controls.Add(this.label1);
     this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
     this.Name = "TTC1";
     this.Text = "Terrible Thick Client <3";
     this.ResumeLayout(false);
     this.PerformLayout();
 }