PasswordStorageEncryptionTool.ps1


<#PSScriptInfo
 
.VERSION 1.01
 
.GUID 6a68268c-9a3e-45a4-860d-483a378efeb5
 
.AUTHOR John Merager
 
.COMPANYNAME
 
.COPYRIGHT 11/11/2020
 
.TAGS Password, Passwords, Storage, Encryption, Encrypt, Decrypt, Passphrase, UI, GUI, Forms
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
Version 1.01:
* Fixed saving history for multiple passphrases
* Added Load on Add checkbox and now auto-loads previously saved under the same passphrase
* Updated description
 
Version 1.0:
Execute example:
powershell.exe -ExecutionPolicy Bypass -file .\PasswordStorageEncryptionTool.ps1
 
Stores encrypted passwords and data to a file. Default is the actual script file.
-File parameter is used to override default file.
Example:
powershell.exe -ExecutionPolicy Bypass -file .\PasswordStorageEncryptionTool.ps1 -File .\MyPasswords.txt
 
How to save passwords:
1. Type in a Passphrase used to encrypt and decrypt your password list
  - pressing ENTER or clicking on LOAD button will load previously saved
2. Type in Passcode (password) you want to save
3. Type in a UserName related to password
4. Type in Path (or URL) related to UserName
5. Enter any notes to encrypt
6. Click on Add button
   a. The information entered will then show on the list below
   b. If checkbox "Save on Add" is checked, saves to file
7. You can also click on Save button to save to file
8. Allowed: Repeat with different Passphrase to encrypt password list under a different Passphrase
 
After saving to file, if you close and open this tool:
1. Type in the Passphrase used to encrypt and decrypt your password list
2. Click on Load button to decrypt list from file
 
In the list (grid), double click on Password (*****) to save to clipboard.
 
In the list (grid), double click on other columns (not Password) to load values above (Passcode,UserName,Path,Notes) from that line on the list.
This will display Passcode if Passcode is checked.
 
It allows you to encrypt data under different/multiple Passphrases.
The Load button will only decrypt data related to the specific Passphrase used to save that data.
 
The Passphrase can be save for multiple computers and users. It can only be decrypted for the specific user(s)+computer(s) it was saved/encrypted from.
 
NOTE: Author is not responsible for lost or stolen passwords or data.
      In general, always assume your encrypted data can be decrypted. It is only a matter of time.
      Do not allow others to have access to your encrypted data.
      Always make a back copy of this script or the file which stores your encrypted data.
#>


<#
 
.DESCRIPTION
Simple Password Storage and Encryption Tool
 
Features:
* Saves passwords into PS1 script file by default or another file if specified
  - Has -File parameter for saving to another file
  - Adv checkbox allows you to modify file path where passwords are saved
* Allows storage of passwords under multiple passphrases into the same file
* All data on row is encrypted (Notes, Password, User, Path, etc...)
* Keeps history of old passwords based on UserName and Path/URL
* Extra tab for encrypting strings with Passphrases
* Able to save passphrase for this computer and this user
* In List: Double-Click on Password (********) to COPY (to clipboard)
* In List: Click on anything other than the password to load row above for editting
* Adv Checkbox to show other features
* Adv: PopOut button will show list of passwords unencrypted
 
#>

Param($File="")
###############################################################################
### Written By: John Merager #
##############################
### 11/11/2020 - Created This Script for Encrypting Text - Version 1.0 - John Merager
###
###############################################################################
### Starting
###############################################################################
write-host "Starting...Please Wait..."
###############################################################################
### Save Error Preference
###############################################################################
#$ErrorPreference=$script:ErrorActionPreference
###############################################################################
### Variables
###############################################################################
$ScriptFullPath=$MyInvocation.MyCommand.Path
if ("$File" -eq "")
 {
  $File=$ScriptFullPath
 }
$CurrentComputer = ([String]$env:COMPUTERNAME).ToUpper()            # Server Name
###############################################################################
### Change Time Default Format
###############################################################################
$currentThread = [System.Threading.Thread]::CurrentThread
$culture = [CultureInfo]::InvariantCulture.Clone()
$culture.DateTimeFormat.ShortDatePattern = 'MM/dd/yyyy'
$culture.DateTimeFormat.ShortTimePattern = 'HH:mm:ss'
$currentThread.CurrentCulture = $culture
###############################################################################
### Global Variables and Load Assembly
###############################################################################

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
$ToolTip = New-Object System.Windows.Forms.ToolTip

###############################################################################
### Functions
###

###############################################################################
### Functions: Always on top
###############################################################################
Function ClickAlwaysOnTop
{
 if ($chkAdvancedDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 $form.topmost=$chkAdvancedAlwaysOnTop.Checked
 if ($chkAdvancedAlwaysOnTop.Checked)
  {
   StatusUpdate $tab.SelectedIndex $null "Checked Always On Top" $null
  }
 else
  {
   StatusUpdate $tab.SelectedIndex $null "Unchecked Always On Top" $null
  }
}

###############################################################################
### Functions: Status Bar - For multiple Tabs
###############################################################################
Function ClickChangeTab
{
 if ($chkAdvancedDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 $StatusBar_P1.Text = $global:TabIndexList[$tab.SelectedIndex].Status
 $StatusBar_P2.Text = $global:TabIndexList[$tab.SelectedIndex].Details
 $StatusBar_P3.Text = $global:TabIndexList[$tab.SelectedIndex].Server
}

###############################################################################
### Functions: Date Time - Not used, but here if needed
###############################################################################

Function UTCtoLocalTime([DateTime]$UTCTime)
{
 if ($chkAdvancedDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 foreach ($UTC in [System.TimeZoneInfo]::GetSystemTimeZones())
  {
   if ($UTC.Id -eq 'UTC')
    {
     return ($UTCTime).AddMinutes(([DateTime]::Now-[TimeZoneInfo]::ConvertTime([DateTime]::Now, $UTC)).TotalMinutes)
    }
  }
}

Function UTCtoLocalTimeMinutes([DateTime]$UTCTime)
{
 if ($chkAdvancedDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 foreach ($UTC in [System.TimeZoneInfo]::GetSystemTimeZones())
  {
   if ($UTC.Id -eq 'UTC')
    {
     return ([DateTime]::Now-[TimeZoneInfo]::ConvertTime([DateTime]::Now, $UTC)).TotalMinutes
    }
  }
}

Function CurrentUTC
{
 if ($chkAdvancedDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 foreach ($UTC in [System.TimeZoneInfo]::GetSystemTimeZones())
  {
   if ($UTC.Id -eq 'UTC')
    {
     return [TimeZoneInfo]::ConvertTime([DateTime]::Now, $UTC)
    }
  }
}


###
### Functions
###############################################################################

###################################################################
#################### Encrypt Tab Functions

###################################################################
##### Encrypt Tab Function:
###################################################################

Function EncryptList_DClick
{
 if ($chkAdvancedDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 if ($dgEncryptData.CurrentCell.ColumnIndex -eq 0)
  {
   [String]($TblEncryptData.DefaultView[$dgEncryptData.CurrentCell.RowIndex][7]) | Set-Clipboard
  }
 elseif ($TblEncryptData.DefaultView[$dgEncryptData.CurrentCell.RowIndex][1] -ne "" -Or $TblEncryptData.DefaultView[$dgEncryptData.CurrentCell.RowIndex][7] -ne "" -Or $TblEncryptData.DefaultView[$dgEncryptData.CurrentCell.RowIndex][2] -ne "")
  {
   $tbxEncryptUserName.Text=[String]($TblEncryptData.DefaultView[$dgEncryptData.CurrentCell.RowIndex][1])
   $tbxEncryptPasscode.Text=[String]($TblEncryptData.DefaultView[$dgEncryptData.CurrentCell.RowIndex][7])
   $tbxEncryptPath.Text=[String]($TblEncryptData.DefaultView[$dgEncryptData.CurrentCell.RowIndex][2])
   $tbxEncryptNotes.Text=[String]($TblEncryptData.DefaultView[$dgEncryptData.CurrentCell.RowIndex][6])
  }


 #$CellValue = [String]($TblDeployStatus.DefaultView[$dgDeployStatus.CurrentCell.RowIndex][$dgDeployStatus.CurrentCell.ColumnIndex])
 ##if ($chkAdvancedDebug.Checked) {write-host $CellValue.replace("><",">`r`n<")}
 #if ($chkAdvancedDebug.Checked) {write-host $CellValue}
 ##$CellValue=$CellValue.replace("`n","`r`n").replace("`r`r","`r")
 ##$CellValue=$CellValue.replace("`r","`r`n").replace("`n`n","`n")
 #OpenTextBox $CellValue
}

Function EncryptHistory_DClick
{
 if ($chkAdvancedDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 if ($dgEncryptHistory.CurrentCell.ColumnIndex -eq 0)
  {
   [String]($TblEncryptHistory.DefaultView[$dgEncryptHistory.CurrentCell.RowIndex][7]) | Set-Clipboard
  }
 elseif ($TblEncryptHistory.DefaultView[$dgEncryptHistory.CurrentCell.RowIndex][1] -ne "" -Or $TblEncryptHistory.DefaultView[$dgEncryptHistory.CurrentCell.RowIndex][7] -ne "" -Or $TblEncryptHistory.DefaultView[$dgEncryptHistory.CurrentCell.RowIndex][2] -ne "")
  {
   $tbxEncryptUserName.Text=[String]($TblEncryptHistory.DefaultView[$dgEncryptHistory.CurrentCell.RowIndex][1])
   $tbxEncryptPasscode.Text=[String]($TblEncryptHistory.DefaultView[$dgEncryptHistory.CurrentCell.RowIndex][7])
   $tbxEncryptPath.Text=[String]($TblEncryptHistory.DefaultView[$dgEncryptHistory.CurrentCell.RowIndex][2])
   $tbxEncryptNotes.Text=[String]($TblEncryptHistory.DefaultView[$dgEncryptHistory.CurrentCell.RowIndex][6])
  }
}

Function EncryptButtonSave
{
 if (!(test-path $tbxEncryptFilePath.Text) -And "$ScriptFullPath" -ne "$($tbxEncryptFilePath.Text)")
  {
   $newcontent ="#EncryptPhrase.Start:`r`n"
   $newcontent+="#EncryptPhrase.End:`r`n"
   $newcontent+="#Encrypted.Start:`r`n"
   $newcontent+="#Encrypted.End:`r`n"
   $newcontent+="#EncryptedHistory.Start:`r`n"
   $newcontent+="#EncryptedHistory.End:`r`n"
   Set-Content $tbxEncryptFilePath.Text $newcontent
  }
 $NewFile=""
 $getlines=$False
 $Needsave=$True
 $Passphrase = $tbxEncryptPassPhrase.Text
 $key = [Byte[]]($Passphrase.PadRight(24).Substring(0,24).ToCharArray())
 $gethistory=$False
 foreach ($line in (Get-Content $tbxEncryptFilePath.Text))
  {
   if (!($getlines) -And !($gethistory))
    {
     $NewFile+="$line`r`n"
    }
   if ($line -like "#Encrypted.Start:*")
    {
     $getlines=$True
    }
   elseif ($line -like "#Encrypted.End:*")
    {
     $getlines=$False
     if ($Needsave)
      {
       $EncryptList=@()
       foreach ($EncryptRow in ($dgEncryptData.rows | Where-Object {$null -ne $_.DataBoundItem.Password}))
        {
         $EncryptList += New-Object PSObject -Property @{
           Password=$EncryptRow.DataBoundItem.HiddenPassword
           UserName=$EncryptRow.DataBoundItem.UserName
           Path=$EncryptRow.DataBoundItem.Path
           Notes=$EncryptRow.DataBoundItem.Notes
           Version=$EncryptRow.DataBoundItem.Version
           Created=$EncryptRow.DataBoundItem.Created
           Updated=$EncryptRow.DataBoundItem.Updated
          }
        }
       $TableJson=ConvertTo-Json $EncryptList
       $encrypted = $TableJson | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString -Key $key
       $NewFile+="$encrypted`r`n"
      }
     $NewFile+="$line`r`n"
     $Needsave=$True
    }
   elseif ($line -like "#EncryptedHistory.Start:*" -And ($chkEncryptSaveHistory.Checked))
    {
     $gethistory=$True
    }
   elseif ($line -like "#EncryptedHistory.End:*")
    {
     $gethistory=$False
     if ($Needsave)
      {
       $EncryptList=@()
       foreach ($EncryptRow in ($dgEncryptHistory.rows | Where-Object {$null -ne $_.DataBoundItem.Password}))
        {
         $EncryptList += New-Object PSObject -Property @{
           Password=$EncryptRow.DataBoundItem.HiddenPassword
           UserName=$EncryptRow.DataBoundItem.UserName
           Path=$EncryptRow.DataBoundItem.Path
           Notes=$EncryptRow.DataBoundItem.Notes
           Version=$EncryptRow.DataBoundItem.Version
           Created=$EncryptRow.DataBoundItem.Created
           Updated=$EncryptRow.DataBoundItem.Updated
          }
        }
       $TableJson=ConvertTo-Json $EncryptList
       $encrypted = $TableJson | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString -Key $key
       $NewFile+="$encrypted`r`n"
      }
     $NewFile+="$line`r`n"
     $Needsave=$True
    }
   elseif ($gethistory)
    {
     try {
       $decryptedTextSecureString = $line | ConvertTo-SecureString -Key $key -ErrorAction Stop
       $cred = New-Object -TypeName System.Management.Automation.PSCredential('dummy', $decryptedTextSecureString)
       $decryptedText = $cred.GetNetworkCredential().Password
      } catch {$decryptedText = ''}
     if ("$decryptedText" -ne "")
      {
       $EncryptList=@()
       $FoundRows=$False
       foreach ($EncryptRow in ($dgEncryptHistory.rows | Where-Object {$null -ne $_.DataBoundItem.HiddenPassword}))
        {
         $FoundRows=$True
         $EncryptList += New-Object PSObject -Property @{
           Password=$EncryptRow.DataBoundItem.HiddenPassword
           UserName=$EncryptRow.DataBoundItem.UserName
           Path=$EncryptRow.DataBoundItem.Path
           Notes=$EncryptRow.DataBoundItem.Notes
           Version=$EncryptRow.DataBoundItem.Version
           Created=$EncryptRow.DataBoundItem.Created
           Updated=$EncryptRow.DataBoundItem.Updated
          }
        }
       $TableJson=ConvertTo-Json $EncryptList
       $encrypted = $TableJson | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString -Key $key
       $Needsave=$False
       if ($FoundRows)
        {
         $NewFile+="$encrypted`r`n"
        }
      }
     else
      {
       $NewFile+="$line`r`n"
      }
    }
   elseif ($getlines)
    {
     try {
       $decryptedTextSecureString = $line | ConvertTo-SecureString -Key $key -ErrorAction Stop
       $cred = New-Object -TypeName System.Management.Automation.PSCredential('dummy', $decryptedTextSecureString)
       $decryptedText = $cred.GetNetworkCredential().Password
      } catch {$decryptedText = ''}
     if ("$decryptedText" -ne "")
      {
       $EncryptList=@()
       $FoundRows=$False
       foreach ($EncryptRow in ($dgEncryptData.rows | Where-Object {$null -ne $_.DataBoundItem.HiddenPassword}))
        {
         $FoundRows=$True
         $VersionRow=([int]$EncryptRow.DataBoundItem.Version)
         $UpdateRow=$EncryptRow.DataBoundItem.Updated
         foreach ($row in ($decryptedText |ConvertFrom-Json))
          {
           if ("$($row.UserName)" -eq "$($EncryptRow.DataBoundItem.UserName)" -And "$($row.Path)" -eq "$($EncryptRow.DataBoundItem.Path)" -And ("$($row.Password)" -ne "$($EncryptRow.DataBoundItem.HiddenPassword)" -Or "$($row.Notes)" -ne "$($EncryptRow.DataBoundItem.Notes)"))
            {
             $VersionRow=([int]$row.Version)+1
             $EncryptRow.DataBoundItem.Version=$VersionRow
             $UpdateRow=(get-date)
             $EncryptRow.DataBoundItem.Updated=$UpdateRow
            }
          }
         $dgEncryptData.Refresh()
         $EncryptList += New-Object PSObject -Property @{
           Password=$EncryptRow.DataBoundItem.HiddenPassword
           UserName=$EncryptRow.DataBoundItem.UserName
           Path=$EncryptRow.DataBoundItem.Path
           Notes=$EncryptRow.DataBoundItem.Notes
           Version=$VersionRow
           Created=$EncryptRow.DataBoundItem.Created
           Updated=$UpdateRow
          }
        }
       $TableJson=ConvertTo-Json $EncryptList
       $encrypted = $TableJson | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString -Key $key
       $Needsave=$False
       if ($FoundRows)
        {
         $NewFile+="$encrypted`r`n"
        }
      }
     else
      {
       $NewFile+="$line`r`n"
      }
    }
  }
 if ($NewFile.length -gt 0)
  {
   $NewFile=$NewFile.substring(0,$NewFile.length-2)
   Set-Content $tbxEncryptFilePath.Text $NewFile
  }
}

Function EncryptButtonLoad
{
 if (!(test-path $tbxEncryptFilePath.Text) -And "$ScriptFullPath" -ne "$($tbxEncryptFilePath.Text)")
  {
   $newcontent ="#EncryptPhrase.Start:`r`n"
   $newcontent+="#EncryptPhrase.End:`r`n"
   $newcontent+="#Encrypted.Start:`r`n"
   $newcontent+="#Encrypted.End:`r`n"
   $newcontent+="#EncryptedHistory.Start:`r`n"
   $newcontent+="#EncryptedHistory.End:`r`n"
   Set-Content $tbxEncryptFilePath.Text $newcontent
  }
 $Passphrase = $tbxEncryptPassPhrase.Text
 $key = [Byte[]]($Passphrase.PadRight(24).Substring(0,24).ToCharArray())
 $getlines=$False
 $gethistory=$False
 $TblEncryptData.Clear()
 $TblEncryptHistory.Clear()
 foreach ($line in (Get-Content $tbxEncryptFilePath.Text))
  {
   if ($line -like "#Encrypted.Start:*")
    {
#write-host "#Encrypted.Start:*"
     $getlines=$True
    }
   elseif ($line -like "#Encrypted.End:*")
    {
#write-host "#Encrypted.End:*"
     $getlines=$False
    }
   elseif ($line -like "#EncryptedHistory.Start:*" -And ($chkEncryptLoadHistory.Checked))
    {
#write-host "#EncryptedHistory.Start:*"
     $gethistory=$True
    }
   elseif ($line -like "#EncryptedHistory.End:*")
    {
#write-host "#EncryptedHistory.End:*"
     $gethistory=$False
    }
   elseif ($getlines)
    {
#write-host "getlines"
     try {
       $decryptedTextSecureString = $line | ConvertTo-SecureString -Key $key -ErrorAction Stop
       $cred = New-Object -TypeName System.Management.Automation.PSCredential('dummy', $decryptedTextSecureString)
       $decryptedText = $cred.GetNetworkCredential().Password
      } catch {$decryptedText = ''}
     if ("$decryptedText" -ne "")
      {
       foreach ($row in ($decryptedText |ConvertFrom-Json))
        {
         $TblEncryptData.Rows.Add(("*" * $row.Password.length),$row.UserName,$row.Path,$row.Version,$row.Created,$row.Updated,$row.Notes,$row.Password)
        }
      }
    }
   elseif ($gethistory)
    {
#write-host "gethistory1"
#write-host "$line"
     try {
       $decryptedTextSecureString = $line | ConvertTo-SecureString -Key $key -ErrorAction Stop
       $cred = New-Object -TypeName System.Management.Automation.PSCredential('dummy', $decryptedTextSecureString)
       $decryptedText = $cred.GetNetworkCredential().Password
      } catch {$decryptedText = ''}
#write-host "gethistoryErr $($Error[0])"
     if ("$decryptedText" -ne "")
      {
#write-host "gethistory2"
       foreach ($row in ($decryptedText |ConvertFrom-Json))
        {
#write-host "gethistory3"
         $TblEncryptHistory.Rows.Add(("*" * $row.Password.length),$row.UserName,$row.Path,$row.Version,$row.Created,$row.Updated,$row.Notes,$row.Password)
        }
      }
    }
  }
}

Function EncryptButtonAdd
{
     $FoundRows=$False
 if ($chkEncryptLoadOnAdd.Checked)
  {
   EncryptButtonLoad
  }
     foreach ($EncryptRow in ($dgEncryptData.rows | Where-Object {$null -ne $_.DataBoundItem.HiddenPassword}))
      {
       if ($EncryptRow.DataBoundItem.UserName -eq $tbxEncryptUserName.Text -And $EncryptRow.DataBoundItem.Path -eq $tbxEncryptPath.Text)
        {
         $FoundRows=$True
         if ($EncryptRow.DataBoundItem.HiddenPassword -ne $tbxEncryptPasscode.Text -Or $EncryptRow.DataBoundItem.Notes -ne $tbxEncryptNotes.Text)
          {
           if ($chkEncryptSaveHistory.Checked)
            {
             $TblEncryptHistory.Rows.Add($EncryptRow.DataBoundItem.Password,$EncryptRow.DataBoundItem.UserName,$EncryptRow.DataBoundItem.Path,$EncryptRow.DataBoundItem.Version,$EncryptRow.DataBoundItem.Created,$EncryptRow.DataBoundItem.Updated,$EncryptRow.DataBoundItem.Notes,$EncryptRow.DataBoundItem.HiddenPassword)
            }
           $EncryptRow.DataBoundItem.Version=([int]$EncryptRow.DataBoundItem.Version)+1
           $EncryptRow.DataBoundItem.Updated=(get-date)
           $EncryptRow.DataBoundItem.Password=("*" * $tbxEncryptPasscode.Text.length)#$tbxEncryptPasscode.Text
           $EncryptRow.DataBoundItem.HiddenPassword=$tbxEncryptPasscode.Text
           $EncryptRow.DataBoundItem.Path=$tbxEncryptPath.Text
           $EncryptRow.DataBoundItem.Notes=$tbxEncryptNotes.Text
          }
         else
          {
           $EncryptRow.DataBoundItem.Updated=(get-date)
          }
        }
      }
     $dgEncryptData.Refresh()
  if (!($FoundRows))
   {
    $TblEncryptData.Rows.Add(("*" * $tbxEncryptPasscode.Text.length),$tbxEncryptUserName.Text,$tbxEncryptPath.Text,1,(get-date),(get-date),$tbxEncryptNotes.Text,$tbxEncryptPasscode.Text)
   }
 if ($chkEncryptAutoSave.Checked)
  {
   EncryptButtonSave
  }
 if ($chkEncryptAutoClear.Checked)
  {
   EncryptButtonClear
  }
}

Function EncryptButtonClear
{
   $tbxEncryptUserName.Text=""
   $tbxEncryptPasscode.Text=""
   $tbxEncryptPath.Text=""
   $tbxEncryptNotes.Text=""
}

Function EncryptButtonSavePhrase
{
 if ("$($tbxEncryptPassPhrase.Text)" -ne "")
  {
   $Passphrase = $tbxEncryptPassPhrase.Text | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString
   $NewFile=""
   $getlines=$False
   $Needsave=$True
   foreach ($line in (Get-Content $ScriptFullPath))
    {
     if (!($getlines))
      {
       $NewFile+="$line`r`n"
      }
     if ($line -like "#EncryptPhrase.Start:*")
      {
       $getlines=$True
      }
     elseif ($line -like "#EncryptPhrase.End:*")
      {
       $getlines=$False
       if ($Needsave)
        {
         $NewFile+="`$Phrasecodes+=`"$Passphrase`"`r`n"
        }
       $NewFile+="$line`r`n"
       $Needsave=$True
      }
     elseif ($getlines)
      {
       if ($line -like "*`$Phrasecodes*+=*`"*`"*")
        {
         $encryptedText=$line.substring($line.indexof("`"")+1,$line.length-$line.indexof("`"")-1)
         $encryptedText=$encryptedText.substring(0,$encryptedText.indexof("`""))
        Try {$decryptedText=[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR((($encryptedText | ConvertTo-SecureString -ErrorAction "Stop"))))}
         Catch {$decryptedText=""}
        }
       else
        {
         $decryptedText=""
        }
       if ("$decryptedText" -ne "")
        {
         $Needsave=$False
         $NewFile+="`$Phrasecodes+=`"$Passphrase`"`r`n"
        }
       else
        {
         $NewFile+="$line`r`n"
        }
      }
    }
   if ($NewFile.length -gt 0)
    {
     $NewFile=$NewFile.substring(0,$NewFile.length-2)
     Set-Content $ScriptFullPath $NewFile
    }
  }
}

Function EncryptButtonLoadHistory # Not used
{
 if ($chkEncryptLoadHistory.Checked)
  {
   if (!(test-path $tbxEncryptFilePath.Text) -And "$ScriptFullPath" -ne "$($tbxEncryptFilePath.Text)")
    {
     $newcontent ="#EncryptPhrase.Start:`r`n"
     $newcontent+="#EncryptPhrase.End:`r`n"
     $newcontent+="#Encrypted.Start:`r`n"
     $newcontent+="#Encrypted.End:`r`n"
     $newcontent+="#EncryptedHistory.Start:`r`n"
     $newcontent+="#EncryptedHistory.End:`r`n"
     Set-Content $tbxEncryptFilePath.Text $newcontent
    }
   $Passphrase = $tbxEncryptPassPhrase.Text
   $key = [Byte[]]($Passphrase.PadRight(24).Substring(0,24).ToCharArray())
   $gethistory=$False
   $TblEncryptHistory.Clear()
   foreach ($line in (Get-Content $tbxEncryptFilePath.Text))
    {
     if ($line -like "#EncryptedHistory.Start:*")
      {
       $gethistory=$True
      }
     elseif ($line -like "#EncryptedHistory.End:*")
      {
       $gethistory=$False
      }
     elseif ($gethistory)
      {
       try {
         $decryptedTextSecureString = $line | ConvertTo-SecureString -Key $key -ErrorAction Stop
         $cred = New-Object -TypeName System.Management.Automation.PSCredential('dummy', $decryptedTextSecureString)
         $decryptedText = $cred.GetNetworkCredential().Password
        } catch {$decryptedText = ''}
       if ("$decryptedText" -ne "")
        {
         foreach ($row in ($decryptedText |ConvertFrom-Json))
          {
           $TblEncryptHistory.Rows.Add(("*" * $row.Password.length),$row.UserName,$row.Path,$row.Version,$row.Created,$row.Updated,$row.Notes,$row.Password)
          }
        }
      }
    }
  }
}

Function EncryptButtonSaveHistory
{
 if (!($chkEncryptSaveHistory.Checked))
  {
   $TblEncryptHistory.Clear()
  }
}

Function EncryptButtonPopup
{
 if ($tab1.SelectedIndex -eq 0)
  {
       $EncryptList=@()
       foreach ($EncryptRow in ($dgEncryptData.rows | Where-Object {$null -ne $_.DataBoundItem.Password}))
        {
         $EncryptList += New-Object PSObject -Property @{
           Password=$EncryptRow.DataBoundItem.HiddenPassword
           UserName=$EncryptRow.DataBoundItem.UserName
           Path=$EncryptRow.DataBoundItem.Path
           Notes=$EncryptRow.DataBoundItem.Notes
           Version=$EncryptRow.DataBoundItem.Version
           Created=$EncryptRow.DataBoundItem.Created
           Updated=$EncryptRow.DataBoundItem.Updated
          }
        }
  }
 else
  {
       $EncryptList=@()
       foreach ($EncryptRow in ($dgEncryptHistory.rows | Where-Object {$null -ne $_.DataBoundItem.Password}))
        {
         $EncryptList += New-Object PSObject -Property @{
           Password=$EncryptRow.DataBoundItem.HiddenPassword
           UserName=$EncryptRow.DataBoundItem.UserName
           Path=$EncryptRow.DataBoundItem.Path
           Notes=$EncryptRow.DataBoundItem.Notes
           Version=$EncryptRow.DataBoundItem.Version
           Created=$EncryptRow.DataBoundItem.Created
           Updated=$EncryptRow.DataBoundItem.Updated
          }
        }
  }
 $GridResults = New-Object System.Collections.ArrayList
 $GridResults.AddRange(@($EncryptList |Select-Object Password,UserName,Path,Version,Created,Updated,Notes))
 $GridResults | Out-Gridview
}

Function EncryptButtonAdv
{
 if ($chkEncryptAdv.Checked)
  {
   $chkEncryptAutoSave.Visible  = $True
   $chkEncryptAutoClear.Visible  = $True
   $chkEncryptLoadHistory.Visible  = $True
   $chkEncryptLoadOnAdd.Visible  = $True
   $chkEncryptSaveHistory.Visible  = $True
   $btnEncryptSavePhrase.Visible  = $True
   $lblEncryptForThisPhrase.Visible  = $True
   $chkAdvancedDebug.Visible  = $True
   $tbxEncryptFilePath.Visible  = $True
   $lblEncryptFilePath.Visible  = $True
   $btnEncryptPopup.Visible  = $True
  }
 else
  {
   $chkEncryptAutoSave.Visible  = $False
   $chkEncryptAutoClear.Visible  = $False
   $chkEncryptLoadHistory.Visible  = $False
   $chkEncryptLoadOnAdd.Visible  = $False
   $chkEncryptSaveHistory.Visible  = $False
   $btnEncryptSavePhrase.Visible  = $False
   $lblEncryptForThisPhrase.Visible  = $False
   $chkAdvancedDebug.Visible  = $False
   $tbxEncryptFilePath.Visible  = $False
   $lblEncryptFilePath.Visible  = $False
   $btnEncryptPopup.Visible  = $False
  }
}

Function EncryptCheckboxPasscode
{
 If ($chkEncryptPasscode.Checked)
  {
   $tbxEncryptPasscode.PasswordChar = $null
  }
 Else
  {
   $tbxEncryptPasscode.PasswordChar = '*'
  }
}

Function ExtraEncryptByPhrase
{
 if ($chkExtraByPhrase.Checked)
  {
   $Passphrase = $tbxEncryptPassPhrase.Text
  }
 else
  {
   $Passphrase = $tbxExtraPassPhrase.Text
  }
 $key = [Byte[]]($Passphrase.PadRight(24).Substring(0,24).ToCharArray())
 $tbxExtraByPhrase.Text = $tbxExtraByPhrase.Text | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString -Key $key
}

Function ExtraDecryptByPhrase
{
 if ($chkExtraByPhrase.Checked)
  {
   $Passphrase = $tbxEncryptPassPhrase.Text
  }
 else
  {
   $Passphrase = $tbxExtraPassPhrase.Text
  }
 $OrigText=$tbxExtraByPhrase.Text
 $key = [Byte[]]($Passphrase.PadRight(24).Substring(0,24).ToCharArray())
 Try {
   $decryptedTextSecureString = $tbxExtraByPhrase.Text | ConvertTo-SecureString -Key $key -ErrorAction Stop
   $cred = New-Object -TypeName System.Management.Automation.PSCredential('dummy', $decryptedTextSecureString)
   $tbxExtraByPhrase.Text = $cred.GetNetworkCredential().Password
  } Catch {$tbxExtraByPhrase.Text=$OrigText}
}

Function ExtraEncryptByUserComputer
{
 $tbxExtraByUserComputer.Text = $tbxExtraByUserComputer.Text | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString
}

Function ExtraDecryptByUserComputer
{
 $OrigText=$tbxExtraByUserComputer.Text
 Try {$tbxExtraByUserComputer.Text=[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR((($tbxExtraByUserComputer.Text | ConvertTo-SecureString -ErrorAction "Stop"))))}
 Catch {$tbxExtraByUserComputer.Text=$OrigText}
}

Function ExtraCopyByPhrase
{
 $tbxExtraByPhrase.Text | Set-Clipboard
}

Function ExtraCopyByUserComputer
{
 $tbxExtraByUserComputer.Text | Set-Clipboard
}

Function ExtraClearByPhrase
{
 $tbxExtraByPhrase.Text=""
}

Function ExtraClearByUserComputer
{
 $tbxExtraByUserComputer.Text=""
}

Function ExtraBrowseInputFile
{
 $OpenFileDialog = New-Object System.Windows.Forms.openFileDialog
 $OpenFileDialog.ShowDialog()
 $tbxExtraInputFile.Text=$OpenFileDialog.FileName
}

Function ExtraBrowseOutputFile
{
 $OpenFileDialog = New-Object System.Windows.Forms.openFileDialog
 $OpenFileDialog.ShowDialog()
 $tbxExtraOutputFile.Text=$OpenFileDialog.FileName
}

Function ExtraEncryptFileByPhrase
{
 if ($chkExtraFileByPhrase.Checked)
  {
   $Passphrase=$tbxEncryptPassPhrase.Text
  }
 else
  {
   $Passphrase=$tbxExtraFilePhrase.Text
  }
 if ($chkExtraSameFile.Checked)
  {
   $TargetFile=$tbxExtraInputFile.Text
  }
 else
  {
   $TargetFile=$tbxExtraOutputFile.Text
  }
 $key = [Byte[]]($Passphrase.PadRight(24).Substring(0,24).ToCharArray())
 $decryptedText = Get-Content $tbxExtraInputFile.Text |Out-String
 $decryptedText=$decryptedText.substring(0,$decryptedText.length-2)
 $encryptedText = $decryptedText | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString -Key $key
 Set-Content $TargetFile $encryptedText
}

Function ExtraDecryptFileByPhrase
{
 if ($chkExtraFileByPhrase.Checked)
  {
   $Passphrase=$tbxEncryptPassPhrase.Text
  }
 else
  {
   $Passphrase=$tbxExtraFilePhrase.Text
  }
 if ($chkExtraSameFile.Checked)
  {
   $TargetFile=$tbxExtraInputFile.Text
  }
 else
  {
   $TargetFile=$tbxExtraOutputFile.Text
  }
 $key = [Byte[]]($Passphrase.PadRight(24).Substring(0,24).ToCharArray())
#Try {
 $decryptedText = Get-Content $tbxExtraInputFile.Text | ConvertTo-SecureString -Key $key -ErrorAction Stop
   $cred = New-Object -TypeName System.Management.Automation.PSCredential('dummy', $decryptedText)
  Set-Content $TargetFile ($cred.GetNetworkCredential().Password)
# } Catch {write-host "ERROR: $($Error[0])"}
}

Function ExtraEncryptFileByUserComputer
{
 if ($chkExtraSameFile.Checked)
  {
   $TargetFile=$tbxExtraInputFile.Text
  }
 else
  {
   $TargetFile=$tbxExtraOutputFile.Text
  }
 $decryptedText = Get-Content $tbxExtraInputFile.Text |Out-String
 $decryptedText=$decryptedText.substring(0,$decryptedText.length-2)
 $encryptedText = $decryptedText | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString
 Set-Content $TargetFile $encryptedText
}

Function ExtraDecryptFileByUserComputer
{
 if ($chkExtraSameFile.Checked)
  {
   $TargetFile=$tbxExtraInputFile.Text
  }
 else
  {
   $TargetFile=$tbxExtraOutputFile.Text
  }
# Try {
 $decryptedText=[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR(((Get-Content $tbxExtraInputFile.Text | ConvertTo-SecureString -ErrorAction "Stop"))))
  Set-Content $TargetFile $decryptedText
# } Catch {write-host "ERROR: $($Error[0])"}
}

#################### Encrypt Tab Functions
###################################################################

###################################################################
#################### Form Size Functions

Function FormSizeChanged
{
 if ($chkAdvancedDebug.Checked) {write-host "Function $($MyInvocation.Line)"}
 if ($Form.Width -gt 10)
  {
   $tab.Width=$Form.Width-20
  }
 if ($Form.Height -gt 100)
  {
   $tab.Height=$Form.Height-65
   if ($tab.Height -gt (61+$tab1.Top))
    {
     $tab1.Height=($tab.Height-$tab1.Top-26)
    }
  }
 if ($Form.Width -gt 10)
  {
   if ($tab.Width -gt 20)
    {
     $tab1.Width=$tab.Width-8
    }
   $dgEncryptData.Width=$Form.Width-36
   $dgEncryptHistory.Width=$Form.Width-36
  }
 if ($Form.Height -gt 40)
  {
   if ($Form.Height -gt 100)
    {
     $dgEncryptData.Height=$Form.Height-95-$dgEncryptData.Top
     $dgEncryptHistory.Height=$Form.Height-95-$dgEncryptHistory.Top
     if ($Form.Height -gt ($tab1.Top+16))
      {
       $dgEncryptData.Height=$Form.Height-$tab1.Top-117-$dgEncryptData.Top
       $dgEncryptHistory.Height=$Form.Height-$tab1.Top-117-$dgEncryptHistory.Top
      }
    }
  }
#write-host "LAST $($tab.Width) $($Form.Width)"
}
#################### Form Size Functions
###################################################################

###############################################################################
### ### End Functions ### ###
###############################################################################

##############################################################################################################################################################
##############################################################################################################################################################
##############################################################################################################################################################

###############################################################################
### ### Create GUI ### ###
###############################################################################
$form = new-object System.Windows.Forms.form

#####################################################################
### Create Tabs
#####################################################################
$tab = new-object System.Windows.Forms.tabcontrol
$tab.Location = New-object System.Drawing.Point(1, 1)
$tab.Size = New-object System.Drawing.Size(990, 570)
$tab.SelectedIndex = 0
$tab.TabIndex = 0
$tab.Add_SelectedIndexChanged({ClickChangeTab})

$tab1 = new-object System.Windows.Forms.tabcontrol
$tab1.Location = New-object System.Drawing.Point(0, 119)#119
$tab1.Size = New-object System.Drawing.Size(($tab.Width-8), ($tab.Height-$tab1.Top-26))
$tab1.SelectedIndex = 0
$tab1.TabIndex = 0
#$tab1.Add_SelectedIndexChanged({ClickChangeTab})


#####################################################################
### Tab Drawing: Encrypt
#####################################################################

##### Tabs:
$tabEncrypt   = new-object System.Windows.Forms.tabpage
##### Add Tab:
$tabEncrypt.Text     = "Encrypt"
$tabEncrypt.Size     = New-object System.Drawing.Size(950, 450)
$tabEncrypt.TabIndex = $tab.TabCount
$tab.controls.add($tabEncrypt)

$lblEncryptPassPhrase           = New-Object System.Windows.Forms.Label
$lblEncryptPassPhrase.Location  = New-Object System.Drawing.Size(5,3)
$lblEncryptPassPhrase.Size      = New-Object System.Drawing.Size(69,15)
$lblEncryptPassPhrase.Text      = "Passphrase"
$lblEncryptPassPhrase.Add_MouseHover({$ToolTip.SetToolTip($this,"Used to encrypt and decrypt list and history below")})
$tabEncrypt.Controls.Add($lblEncryptPassPhrase)

#################################
### Decrypt Phase Phrases
###

$Phrasecodes=@()
$Phrasecode=""
### DO NOT MODIFY THIS:
#EncryptPhrase.Start:
#EncryptPhrase.End:
### DO NOT MODIFY!

foreach ($encryptedText in $Phrasecodes)
 {
  if ($Phrasecode -eq "")
   {
    Try {$Phrasecode=[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR((($encryptedText | ConvertTo-SecureString -ErrorAction "Stop"))))}
     Catch {$Phrasecode=""}
   }
 }

###
### Decrypt Phase Phrases
#################################

$tbxEncryptPassPhrase = New-Object System.Windows.Forms.MaskedTextBox
$tbxEncryptPassPhrase.PasswordChar = '*'
 $tbxEncryptPassPhrase.Location = New-Object System.Drawing.Size(72,0)
 $tbxEncryptPassPhrase.Size = New-Object System.Drawing.Size(98,10)
 $tbxEncryptPassPhrase.Height = 30
$tbxEncryptPassPhrase.Text=$Phrasecode
$tbxEncryptPassPhrase.Add_KeyUp({
    if ($_.KeyCode -eq "Enter")
     {
      EncryptButtonLoad
     }
})
$tbxEncryptPassPhrase.Add_MouseHover({$ToolTip.SetToolTip($this,"Used to encrypt and decrypt list and history below")})
$tabEncrypt.Controls.Add($tbxEncryptPassPhrase)

$btnEncryptLoad          = new-object System.Windows.Forms.Button
$btnEncryptLoad.Location = new-object System.Drawing.Size(8,25)
$btnEncryptLoad.Size     = new-object System.Drawing.Size(60,23)
$btnEncryptLoad.Text     = "Load"
$btnEncryptLoad.Enabled  = $True
$btnEncryptLoad.Add_Click({EncryptButtonLoad})
$btnEncryptLoad.Add_MouseHover({$ToolTip.SetToolTip($this,"Load data from file based on Passphrase")})
$tabEncrypt.Controls.Add($btnEncryptLoad)


$tbxEncryptPasscode = New-Object System.Windows.Forms.MaskedTextBox
$tbxEncryptPasscode.PasswordChar = $null
 $tbxEncryptPasscode.Location = New-Object System.Drawing.Size(170,20)
 $tbxEncryptPasscode.Size = New-Object System.Drawing.Size(200,10)
 $tbxEncryptPasscode.Height = 30
$tbxEncryptPasscode.Text=""
$tbxEncryptPasscode.Add_MouseHover({$ToolTip.SetToolTip($this,"Password or Passcode you want to save")})
$tabEncrypt.Controls.Add($tbxEncryptPasscode)


$tbxEncryptUserName = New-Object System.Windows.Forms.TextBox
 $tbxEncryptUserName.Location = New-Object System.Drawing.Size(170,40)
 $tbxEncryptUserName.Size = New-Object System.Drawing.Size(200,10)
 $tbxEncryptUserName.Height = 30
$tbxEncryptUserName.Text=""
$tbxEncryptUserName.Add_MouseHover({$ToolTip.SetToolTip($this,"Usually user or email")})
$tabEncrypt.Controls.Add($tbxEncryptUserName)

$tbxEncryptPath = New-Object System.Windows.Forms.TextBox
 $tbxEncryptPath.Location = New-Object System.Drawing.Size(170,60)
 $tbxEncryptPath.Size = New-Object System.Drawing.Size(200,10)
 $tbxEncryptPath.Height = 30
$tbxEncryptPath.Text=""
$tbxEncryptPath.Add_MouseHover({$ToolTip.SetToolTip($this,"Path,URL,Server,Domain, or Location of User")})
$tabEncrypt.Controls.Add($tbxEncryptPath)

$tbxEncryptNotes = New-Object System.Windows.Forms.TextBox
 $tbxEncryptNotes.Location = New-Object System.Drawing.Size(380,20)
 $tbxEncryptNotes.Size = New-Object System.Drawing.Size(600,100)
 $tbxEncryptNotes.Multiline=$true
$tbxEncryptNotes.WordWrap=$False
$tbxEncryptNotes.ScrollBars="Both"
$tbxEncryptNotes.Text=""
$tbxEncryptNotes.Add_MouseHover({$ToolTip.SetToolTip($this,"Notes or long strings/keys. This is also encrypted")})
$tabEncrypt.Controls.Add($tbxEncryptNotes)

$btnEncryptAdd          = new-object System.Windows.Forms.Button
$btnEncryptAdd.Location = new-object System.Drawing.Size(170,80)
$btnEncryptAdd.Size     = new-object System.Drawing.Size(60,23)
$btnEncryptAdd.Text     = "Add"
$btnEncryptAdd.Enabled  = $True
$btnEncryptAdd.Add_Click({EncryptButtonAdd})
$btnEncryptAdd.Add_MouseHover({$ToolTip.SetToolTip($this,"Adds to list below. If User+Path match, updates Version+Updated date")})
$tabEncrypt.Controls.Add($btnEncryptAdd)

$btnEncryptSave          = new-object System.Windows.Forms.Button
$btnEncryptSave.Location = new-object System.Drawing.Size(8,80)
$btnEncryptSave.Size     = new-object System.Drawing.Size(60,23)
$btnEncryptSave.Text     = "Save"
$btnEncryptSave.Enabled  = $True
$btnEncryptSave.Add_Click({EncryptButtonSave})
$btnEncryptSave.Add_MouseHover({$ToolTip.SetToolTip($this,"Saves List (and history) below to file")})
$tabEncrypt.Controls.Add($btnEncryptSave)

$btnEncryptSavePhrase          = new-object System.Windows.Forms.Button
$btnEncryptSavePhrase.Location = new-object System.Drawing.Size(170,0)
$btnEncryptSavePhrase.Size     = new-object System.Drawing.Size(80,23)
$btnEncryptSavePhrase.Text     = "Save Phrase"
$btnEncryptSavePhrase.Enabled  = $True
$btnEncryptSavePhrase.Add_Click({EncryptButtonSavePhrase})
$btnEncryptSavePhrase.Add_MouseHover({$ToolTip.SetToolTip($this,"Encrypts and saves to this script. Only decrypts for current user and current computer")})
$tabEncrypt.Controls.Add($btnEncryptSavePhrase)

$btnEncryptPopup          = new-object System.Windows.Forms.Button
$btnEncryptPopup.Location = new-object System.Drawing.Size(100,80)
$btnEncryptPopup.Size     = new-object System.Drawing.Size(60,23)
$btnEncryptPopup.Text     = "PopOut"
$btnEncryptPopup.Enabled  = $True
$btnEncryptPopup.Add_Click({EncryptButtonPopup})
$btnEncryptPopup.Add_MouseHover({$ToolTip.SetToolTip($this,"Opens a Grid View popup to view all passwords in List or History tabs")})
$tabEncrypt.Controls.Add($btnEncryptPopup)

$tbxEncryptFilePath = New-Object System.Windows.Forms.TextBox
$tbxEncryptFilePath.Location = New-Object System.Drawing.Size(480,0)
$tbxEncryptFilePath.Size = New-Object System.Drawing.Size(440,10)
$tbxEncryptFilePath.Height = 30
$tbxEncryptFilePath.Text="$File"
$tbxEncryptFilePath.Add_MouseHover({$ToolTip.SetToolTip($this,"File to store List/History below. Script path is default. Override with -File parameter")})
$tabEncrypt.Controls.Add($tbxEncryptFilePath)

$lblEncryptForThisPhrase           = New-Object System.Windows.Forms.Label
$lblEncryptForThisPhrase.Location  = New-Object System.Drawing.Size(250,3)
$lblEncryptForThisPhrase.Size      = New-Object System.Drawing.Size(130,15)
$lblEncryptForThisPhrase.Text      = "for this user+computer"
$lblEncryptForThisPhrase.Add_MouseHover({$ToolTip.SetToolTip($this,"Used to encrypt and decrypt list and history below")})
$tabEncrypt.Controls.Add($lblEncryptForThisPhrase)

$chkEncryptAutoSave          = New-Object System.Windows.Forms.CheckBox
$chkEncryptAutoSave.Location = New-Object System.Drawing.Size(240,80)
$chkEncryptAutoSave.size     = new-object System.Drawing.Size(90,20)
$chkEncryptAutoSave.Text     = "Save on Add"
$chkEncryptAutoSave.Checked  = $True
$chkEncryptAutoSave.Add_MouseHover({$ToolTip.SetToolTip($this,"Auto saves to file when clicking on Add button")})
$tabEncrypt.controls.add($chkEncryptAutoSave)

$btnEncryptClear          = new-object System.Windows.Forms.Button
$btnEncryptClear.Location = new-object System.Drawing.Size(330,80)
$btnEncryptClear.Size     = new-object System.Drawing.Size(45,23)
$btnEncryptClear.Text     = "Clear"
$btnEncryptClear.Enabled  = $True
$btnEncryptClear.Add_Click({EncryptButtonClear})
$btnEncryptClear.Add_MouseHover({$ToolTip.SetToolTip($this,"Clears the fields above")})
$tabEncrypt.Controls.Add($btnEncryptClear)

$chkEncryptAutoClear          = New-Object System.Windows.Forms.CheckBox
$chkEncryptAutoClear.Location = New-Object System.Drawing.Size(240,100)
$chkEncryptAutoClear.size     = new-object System.Drawing.Size(90,20)
$chkEncryptAutoClear.Text     = "Clear on Add"
$chkEncryptAutoClear.Checked  = $True
$chkEncryptAutoClear.Add_MouseHover({$ToolTip.SetToolTip($this,"Clears values when clicking on Add button")})
$tabEncrypt.controls.add($chkEncryptAutoClear)

$chkEncryptLoadHistory          = New-Object System.Windows.Forms.CheckBox
$chkEncryptLoadHistory.Location = New-Object System.Drawing.Size(5,45)
$chkEncryptLoadHistory.size     = new-object System.Drawing.Size(90,20)
$chkEncryptLoadHistory.Text     = "Load History"
$chkEncryptLoadHistory.Checked  = $True
$chkEncryptLoadHistory.Add_MouseHover({$ToolTip.SetToolTip($this,"When clicking on Load button, load history from file to History tab")})
$tabEncrypt.controls.add($chkEncryptLoadHistory)

$chkEncryptLoadOnAdd          = New-Object System.Windows.Forms.CheckBox
$chkEncryptLoadOnAdd.Location = New-Object System.Drawing.Size(5,61)
$chkEncryptLoadOnAdd.size     = new-object System.Drawing.Size(90,20)
$chkEncryptLoadOnAdd.Text     = "Load On Add"
$chkEncryptLoadOnAdd.Checked  = $True
$chkEncryptLoadOnAdd.Add_MouseHover({$ToolTip.SetToolTip($this,"Loads previously saved encrypted data for this passphrase")})
$tabEncrypt.controls.add($chkEncryptLoadOnAdd)

$chkEncryptSaveHistory          = New-Object System.Windows.Forms.CheckBox
$chkEncryptSaveHistory.Location = New-Object System.Drawing.Size(05,100)
$chkEncryptSaveHistory.size     = new-object System.Drawing.Size(90,20)
$chkEncryptSaveHistory.Text     = "Save History"
$chkEncryptSaveHistory.Checked  = $True
$chkEncryptSaveHistory.Add_MouseHover({$ToolTip.SetToolTip($this,"When clicking on Save button, save anything listed in History to file")})
$tabEncrypt.controls.add($chkEncryptSaveHistory)

$chkEncryptPasscode          = New-Object System.Windows.Forms.CheckBox
$chkEncryptPasscode.Location = New-Object System.Drawing.Size(85,21)
$chkEncryptPasscode.size     = new-object System.Drawing.Size(75,20)
$chkEncryptPasscode.Text     = "Passcode"
$chkEncryptPasscode.Checked  = $True
$chkEncryptPasscode.Add_Click({EncryptCheckboxPasscode})
$chkEncryptPasscode.Add_MouseHover({$ToolTip.SetToolTip($this,"Uncheck to hide passcode")})
$tabEncrypt.controls.add($chkEncryptPasscode)

$lblEncryptUserName           = New-Object System.Windows.Forms.Label
$lblEncryptUserName.Location  = New-Object System.Drawing.Size(100,43)
$lblEncryptUserName.Size      = New-Object System.Drawing.Size(60,15)
$lblEncryptUserName.Text      = "UserName"
$lblEncryptUserName.Add_MouseHover({$ToolTip.SetToolTip($this,"Usually user or email")})
$tabEncrypt.Controls.Add($lblEncryptUserName)

$lblEncryptPath           = New-Object System.Windows.Forms.Label
$lblEncryptPath.Location  = New-Object System.Drawing.Size(100,63)
$lblEncryptPath.Size      = New-Object System.Drawing.Size(60,15)
$lblEncryptPath.Text      = "Path/URL"
$lblEncryptPath.Add_MouseHover({$ToolTip.SetToolTip($this,"Path,URL,Server,Domain, or Location of User")})
$tabEncrypt.Controls.Add($lblEncryptPath)

$lblEncryptNotes           = New-Object System.Windows.Forms.Label
$lblEncryptNotes.Location  = New-Object System.Drawing.Size(380,3)
$lblEncryptNotes.Size      = New-Object System.Drawing.Size(50,15)
$lblEncryptNotes.Text      = "Notes"
$lblEncryptNotes.Add_MouseHover({$ToolTip.SetToolTip($this,"Notes or long strings/keys. This is also encrypted")})
$tabEncrypt.Controls.Add($lblEncryptNotes)

$lblEncryptFilePath           = New-Object System.Windows.Forms.Label
$lblEncryptFilePath.Location  = New-Object System.Drawing.Size(450,3)
$lblEncryptFilePath.Size      = New-Object System.Drawing.Size(30,15)
$lblEncryptFilePath.Text      = "File:"
$lblEncryptFilePath.Add_MouseHover({$ToolTip.SetToolTip($this,"File to store List/History below. Script path is default. Override with -File parameter")})
$tabEncrypt.Controls.Add($lblEncryptFilePath)

$chkEncryptAdv          = New-Object System.Windows.Forms.CheckBox
$chkEncryptAdv.Location = New-Object System.Drawing.Size(930,3)
$chkEncryptAdv.size     = new-object System.Drawing.Size(45,20)
$chkEncryptAdv.Text     = "Adv"
$chkEncryptAdv.Checked  = $False
$chkEncryptAdv.Add_Click({EncryptButtonAdv})
$chkEncryptAdv.Add_MouseHover({$ToolTip.SetToolTip($this,"Shows additional options")})
$tabEncrypt.Controls.Add($chkEncryptAdv)

$chkAdvancedDebug          = New-Object System.Windows.Forms.CheckBox
$chkAdvancedDebug.Location = New-Object System.Drawing.Size(1000,3)
$chkAdvancedDebug.size     = new-object System.Drawing.Size(175,20)
$chkAdvancedDebug.Text     = "Debug"
$chkAdvancedDebug.Checked  = $False
$chkAdvancedDebug.Add_MouseHover({$ToolTip.SetToolTip($this,"Displays additional information in the powershell command prompt")})
$tabEncrypt.Controls.Add($chkAdvancedDebug)

$chkAdvancedAlwaysOnTop          = New-Object System.Windows.Forms.CheckBox
$chkAdvancedAlwaysOnTop.Location = New-Object System.Drawing.Size(1000,23)
$chkAdvancedAlwaysOnTop.size     = new-object System.Drawing.Size(175,20)
$chkAdvancedAlwaysOnTop.Text     = "Always On Top"
$chkAdvancedAlwaysOnTop.Checked  = $form.topmost
$chkAdvancedAlwaysOnTop.Add_Click({ClickAlwaysOnTop})
$chkAdvancedAlwaysOnTop.Add_MouseHover({$ToolTip.SetToolTip($this,"Stays in forground")})
#$tabEncrypt.Controls.Add($chkAdvancedAlwaysOnTop)
#Save for later

$tabEncryptData   = new-object System.Windows.Forms.tabpage
$tabEncryptData.Text     = "List"
$tabEncryptData.Size     = New-object System.Drawing.Size(950, 440)#950
$tabEncryptData.TabIndex = $tab1.TabCount
$tab1.controls.add($tabEncryptData)

$tabEncryptHistory   = new-object System.Windows.Forms.tabpage
$tabEncryptHistory.Text     = "History"
$tabEncryptHistory.Size     = New-object System.Drawing.Size(950, 440)#950
$tabEncryptHistory.TabIndex = $tab1.TabCount
$tab1.controls.add($tabEncryptHistory)

$tabEncryptExtra   = new-object System.Windows.Forms.tabpage
$tabEncryptExtra.Text     = "Extra"
$tabEncryptExtra.Size     = New-object System.Drawing.Size(950, 440)#950
$tabEncryptExtra.TabIndex = $tab1.TabCount
$tab1.controls.add($tabEncryptExtra)

$lblExtraByPhrase           = New-Object System.Windows.Forms.Label
$lblExtraByPhrase.Location  = New-Object System.Drawing.Size(5,3)
$lblExtraByPhrase.Size      = New-Object System.Drawing.Size(125,15)
$lblExtraByPhrase.Text      = "Encrypt by Phrase"
$lblExtraByPhrase.Add_MouseHover({$ToolTip.SetToolTip($this,"Encrypt with Passphrase")})
$tabEncryptExtra.Controls.Add($lblExtraByPhrase)

$btnExtraByPhraseEncrypt          = new-object System.Windows.Forms.Button
$btnExtraByPhraseEncrypt.Location = new-object System.Drawing.Size(8,20)
$btnExtraByPhraseEncrypt.Size     = new-object System.Drawing.Size(60,23)
$btnExtraByPhraseEncrypt.Text     = "Encrypt"
$btnExtraByPhraseEncrypt.Enabled  = $True
$btnExtraByPhraseEncrypt.Add_Click({ExtraEncryptByPhrase})
$btnExtraByPhraseEncrypt.Add_MouseHover({$ToolTip.SetToolTip($this,"Encrypt text with Passphrase")})
$tabEncryptExtra.Controls.Add($btnExtraByPhraseEncrypt)

$btnExtraByPhraseDecrypt          = new-object System.Windows.Forms.Button
$btnExtraByPhraseDecrypt.Location = new-object System.Drawing.Size(80,20)
$btnExtraByPhraseDecrypt.Size     = new-object System.Drawing.Size(60,23)
$btnExtraByPhraseDecrypt.Text     = "Decrypt"
$btnExtraByPhraseDecrypt.Enabled  = $True
$btnExtraByPhraseDecrypt.Add_Click({ExtraDecryptByPhrase})
$btnExtraByPhraseDecrypt.Add_MouseHover({$ToolTip.SetToolTip($this,"Decrypt text with Passphrase")})
$tabEncryptExtra.Controls.Add($btnExtraByPhraseDecrypt)

$tbxExtraPassPhrase = New-Object System.Windows.Forms.MaskedTextBox
$tbxExtraPassPhrase.PasswordChar = '*'
 $tbxExtraPassPhrase.Location = New-Object System.Drawing.Size(150,20)
 $tbxExtraPassPhrase.Size = New-Object System.Drawing.Size(100,10)
 $tbxExtraPassPhrase.Height = 30
$tbxExtraPassPhrase.Text=""
$tbxExtraPassPhrase.Add_KeyUp({
    if ($_.KeyCode -eq "Enter")
     {
      EncryptButtonLoad
     }
})
$tbxExtraPassPhrase.Add_MouseHover({$ToolTip.SetToolTip($this,"Passphrase to encrypt and decrypt text")})
$tabEncryptExtra.Controls.Add($tbxExtraPassPhrase)

$tbxExtraByPhrase = New-Object System.Windows.Forms.TextBox
 $tbxExtraByPhrase.Location = New-Object System.Drawing.Size(5,50)
 $tbxExtraByPhrase.Size = New-Object System.Drawing.Size(600,100)
 $tbxExtraByPhrase.Multiline=$true
$tbxExtraByPhrase.WordWrap=$False
$tbxExtraByPhrase.ScrollBars="Both"
$tbxExtraByPhrase.Text=""
$tbxExtraByPhrase.Add_MouseHover({$ToolTip.SetToolTip($this,"Text to Encrypt and Decrypt")})
$tabEncryptExtra.Controls.Add($tbxExtraByPhrase)

$chkExtraByPhrase          = New-Object System.Windows.Forms.CheckBox
$chkExtraByPhrase.Location = New-Object System.Drawing.Size(255,20)
$chkExtraByPhrase.size     = new-object System.Drawing.Size(150,20)
$chkExtraByPhrase.Text     = "Use above phrase"
$chkExtraByPhrase.Checked  = $False
$chkExtraByPhrase.Add_MouseHover({$ToolTip.SetToolTip($this,"Use phrase from the top")})
$tabEncryptExtra.controls.add($chkExtraByPhrase)

$lblExtraByUserComputer           = New-Object System.Windows.Forms.Label
$lblExtraByUserComputer.Location  = New-Object System.Drawing.Size(5,153)
$lblExtraByUserComputer.Size      = New-Object System.Drawing.Size(175,15)
$lblExtraByUserComputer.Text      = "Encrypt by User and Computer"
$lblExtraByUserComputer.Add_MouseHover({$ToolTip.SetToolTip($this,"Encrypt with User and Computer")})
$tabEncryptExtra.Controls.Add($lblExtraByUserComputer)

$btnExtraByUserComputerEncrypt          = new-object System.Windows.Forms.Button
$btnExtraByUserComputerEncrypt.Location = new-object System.Drawing.Size(8,170)
$btnExtraByUserComputerEncrypt.Size     = new-object System.Drawing.Size(60,23)
$btnExtraByUserComputerEncrypt.Text     = "Encrypt"
$btnExtraByUserComputerEncrypt.Enabled  = $True
$btnExtraByUserComputerEncrypt.Add_Click({ExtraEncryptByUserComputer})
$btnExtraByUserComputerEncrypt.Add_MouseHover({$ToolTip.SetToolTip($this,"Encrypt text with User and Computer")})
$tabEncryptExtra.Controls.Add($btnExtraByUserComputerEncrypt)

$btnExtraByUserComputerDecrypt          = new-object System.Windows.Forms.Button
$btnExtraByUserComputerDecrypt.Location = new-object System.Drawing.Size(80,170)
$btnExtraByUserComputerDecrypt.Size     = new-object System.Drawing.Size(60,23)
$btnExtraByUserComputerDecrypt.Text     = "Decrypt"
$btnExtraByUserComputerDecrypt.Enabled  = $True
$btnExtraByUserComputerDecrypt.Add_Click({ExtraDecryptByUserComputer})
$btnExtraByUserComputerDecrypt.Add_MouseHover({$ToolTip.SetToolTip($this,"Decrypt text with User and Computer")})
$tabEncryptExtra.Controls.Add($btnExtraByUserComputerDecrypt)

$tbxExtraByUserComputer = New-Object System.Windows.Forms.TextBox
 $tbxExtraByUserComputer.Location = New-Object System.Drawing.Size(5,200)
 $tbxExtraByUserComputer.Size = New-Object System.Drawing.Size(600,100)
 $tbxExtraByUserComputer.Multiline=$true
$tbxExtraByUserComputer.WordWrap=$False
$tbxExtraByUserComputer.ScrollBars="Both"
$tbxExtraByUserComputer.Text=""
$tbxExtraByUserComputer.Add_MouseHover({$ToolTip.SetToolTip($this,"Text to Encrypt or Decrypt by User and Computer")})
$tabEncryptExtra.Controls.Add($tbxExtraByUserComputer)

$btnExtraByUserComputerCopy          = new-object System.Windows.Forms.Button
$btnExtraByUserComputerCopy.Location = new-object System.Drawing.Size(400,170)
$btnExtraByUserComputerCopy.Size     = new-object System.Drawing.Size(50,23)
$btnExtraByUserComputerCopy.Text     = "Copy"
$btnExtraByUserComputerCopy.Enabled  = $True
$btnExtraByUserComputerCopy.Add_Click({ExtraCopyByUserComputer})
$btnExtraByUserComputerCopy.Add_MouseHover({$ToolTip.SetToolTip($this,"Copy to Clipboard")})
$tabEncryptExtra.Controls.Add($btnExtraByUserComputerCopy)

$btnExtraByPhraseCopy          = new-object System.Windows.Forms.Button
$btnExtraByPhraseCopy.Location = new-object System.Drawing.Size(400,20)
$btnExtraByPhraseCopy.Size     = new-object System.Drawing.Size(50,23)
$btnExtraByPhraseCopy.Text     = "Copy"
$btnExtraByPhraseCopy.Enabled  = $True
$btnExtraByPhraseCopy.Add_Click({ExtraCopyByPhrase})
$btnExtraByPhraseCopy.Add_MouseHover({$ToolTip.SetToolTip($this,"Copy to Clipboard")})
$tabEncryptExtra.Controls.Add($btnExtraByPhraseCopy)

$btnExtraByUserComputerClear          = new-object System.Windows.Forms.Button
$btnExtraByUserComputerClear.Location = new-object System.Drawing.Size(500,170)
$btnExtraByUserComputerClear.Size     = new-object System.Drawing.Size(50,23)
$btnExtraByUserComputerClear.Text     = "Clear"
$btnExtraByUserComputerClear.Enabled  = $True
$btnExtraByUserComputerClear.Add_Click({ExtraClearByUserComputer})
$btnExtraByUserComputerClear.Add_MouseHover({$ToolTip.SetToolTip($this,"Clear text for encrypting by User and Computer")})
$tabEncryptExtra.Controls.Add($btnExtraByUserComputerClear)

$btnExtraByPhraseClear          = new-object System.Windows.Forms.Button
$btnExtraByPhraseClear.Location = new-object System.Drawing.Size(500,20)
$btnExtraByPhraseClear.Size     = new-object System.Drawing.Size(50,23)
$btnExtraByPhraseClear.Text     = "Clear"
$btnExtraByPhraseClear.Enabled  = $True
$btnExtraByPhraseClear.Add_Click({ExtraClearByPhrase})
$btnExtraByPhraseClear.Add_MouseHover({$ToolTip.SetToolTip($this,"Clear text for encrypting by phrase")})
$tabEncryptExtra.Controls.Add($btnExtraByPhraseClear)

$lblExtraFilesByPhrase           = New-Object System.Windows.Forms.Label
$lblExtraFilesByPhrase.Location  = New-Object System.Drawing.Size(5,303)
$lblExtraFilesByPhrase.Size      = New-Object System.Drawing.Size(140,15)
$lblExtraFilesByPhrase.Text      = "Encrypt Files with Phrase"
$lblExtraFilesByPhrase.Add_MouseHover({$ToolTip.SetToolTip($this,"These Encrypt and Decrypt buttons use a Passphrase")})
$tabEncryptExtra.Controls.Add($lblExtraFilesByPhrase)

$lblExtraFilesByUserComputer           = New-Object System.Windows.Forms.Label
$lblExtraFilesByUserComputer.Location  = New-Object System.Drawing.Size(450,303)
$lblExtraFilesByUserComputer.Size      = New-Object System.Drawing.Size(160,15)
$lblExtraFilesByUserComputer.Text      = "Encrypt By User and Computer"
$lblExtraFilesByUserComputer.Add_MouseHover({$ToolTip.SetToolTip($this,"These Encrypt and Decrypt buttons use the Computer and User for encryption")})
$tabEncryptExtra.Controls.Add($lblExtraFilesByUserComputer)

$lblExtraInputFile           = New-Object System.Windows.Forms.Label
$lblExtraInputFile.Location  = New-Object System.Drawing.Size(3,353)
$lblExtraInputFile.Size      = New-Object System.Drawing.Size(42,15)
$lblExtraInputFile.Text      = "File"
$lblExtraInputFile.Add_MouseHover({$ToolTip.SetToolTip($this,"Input File to Encrypt")})
$tabEncryptExtra.Controls.Add($lblExtraInputFile)

$lblExtraOutputFile           = New-Object System.Windows.Forms.Label
$lblExtraOutputFile.Location  = New-Object System.Drawing.Size(3,373)
$lblExtraOutputFile.Size      = New-Object System.Drawing.Size(46,15)
$lblExtraOutputFile.Text      = "SaveAs"
$lblExtraOutputFile.Add_MouseHover({$ToolTip.SetToolTip($this,"File to save to if different than input file")})
$tabEncryptExtra.Controls.Add($lblExtraOutputFile)

$tbxExtraInputFile = New-Object System.Windows.Forms.TextBox
 $tbxExtraInputFile.Location = New-Object System.Drawing.Size(50,350)
 $tbxExtraInputFile.Size = New-Object System.Drawing.Size(300,10)
 $tbxExtraInputFile.Height = 30
$tbxExtraInputFile.Text=""
$tbxExtraInputFile.Add_MouseHover({$ToolTip.SetToolTip($this,"Input File to Encrypt")})
$tabEncryptExtra.Controls.Add($tbxExtraInputFile)

$tbxExtraOutputFile = New-Object System.Windows.Forms.TextBox
 $tbxExtraOutputFile.Location = New-Object System.Drawing.Size(50,370)
 $tbxExtraOutputFile.Size = New-Object System.Drawing.Size(300,10)
 $tbxExtraOutputFile.Height = 30
$tbxExtraOutputFile.Text=""
$tbxExtraOutputFile.Add_MouseHover({$ToolTip.SetToolTip($this,"File to save to if different than input file")})
$tabEncryptExtra.Controls.Add($tbxExtraOutputFile)

$btnExtraBrowseInput          = new-object System.Windows.Forms.Button
$btnExtraBrowseInput.Location = new-object System.Drawing.Size(355,350)
$btnExtraBrowseInput.Size     = new-object System.Drawing.Size(50,23)
$btnExtraBrowseInput.Text     = "Browse"
$btnExtraBrowseInput.Enabled  = $True
$btnExtraBrowseInput.Add_Click({ExtraBrowseInputFile})
$btnExtraBrowseInput.Add_MouseHover({$ToolTip.SetToolTip($this,"Browse for input file")})
$tabEncryptExtra.Controls.Add($btnExtraBrowseInput)

$btnExtraBrowseOutput          = new-object System.Windows.Forms.Button
$btnExtraBrowseOutput.Location = new-object System.Drawing.Size(355,370)
$btnExtraBrowseOutput.Size     = new-object System.Drawing.Size(50,23)
$btnExtraBrowseOutput.Text     = "Browse"
$btnExtraBrowseOutput.Enabled  = $True
$btnExtraBrowseOutput.Add_Click({ExtraBrowseOutputFile})
$btnExtraBrowseOutput.Add_MouseHover({$ToolTip.SetToolTip($this,"Browse for output file to save to")})
$tabEncryptExtra.Controls.Add($btnExtraBrowseOutput)

$btnExtraFileByPhraseEncrypt          = new-object System.Windows.Forms.Button
$btnExtraFileByPhraseEncrypt.Location = new-object System.Drawing.Size(8,320)
$btnExtraFileByPhraseEncrypt.Size     = new-object System.Drawing.Size(60,23)
$btnExtraFileByPhraseEncrypt.Text     = "Encrypt"
$btnExtraFileByPhraseEncrypt.Enabled  = $True
$btnExtraFileByPhraseEncrypt.Add_Click({ExtraEncryptFileByPhrase})
$btnExtraFileByPhraseEncrypt.Add_MouseHover({$ToolTip.SetToolTip($this,"Encrypt with Passphrase")})
$tabEncryptExtra.Controls.Add($btnExtraFileByPhraseEncrypt)

$btnExtraFileByPhraseDecrypt          = new-object System.Windows.Forms.Button
$btnExtraFileByPhraseDecrypt.Location = new-object System.Drawing.Size(80,320)
$btnExtraFileByPhraseDecrypt.Size     = new-object System.Drawing.Size(60,23)
$btnExtraFileByPhraseDecrypt.Text     = "Decrypt"
$btnExtraFileByPhraseDecrypt.Enabled  = $True
$btnExtraFileByPhraseDecrypt.Add_Click({ExtraDecryptFileByPhrase})
$btnExtraFileByPhraseDecrypt.Add_MouseHover({$ToolTip.SetToolTip($this,"Decrypt with Passphrase")})
$tabEncryptExtra.Controls.Add($btnExtraFileByPhraseDecrypt)

$btnExtraFileByUserComputerEncrypt          = new-object System.Windows.Forms.Button
$btnExtraFileByUserComputerEncrypt.Location = new-object System.Drawing.Size(450,320)
$btnExtraFileByUserComputerEncrypt.Size     = new-object System.Drawing.Size(60,23)
$btnExtraFileByUserComputerEncrypt.Text     = "Encrypt"
$btnExtraFileByUserComputerEncrypt.Enabled  = $True
$btnExtraFileByUserComputerEncrypt.Add_Click({ExtraEncryptFileByUserComputer})
$btnExtraFileByUserComputerEncrypt.Add_MouseHover({$ToolTip.SetToolTip($this,"Encrypt with User and Computer")})
$tabEncryptExtra.Controls.Add($btnExtraFileByUserComputerEncrypt)

$btnExtraFileByUserComputerDecrypt          = new-object System.Windows.Forms.Button
$btnExtraFileByUserComputerDecrypt.Location = new-object System.Drawing.Size(520,320)
$btnExtraFileByUserComputerDecrypt.Size     = new-object System.Drawing.Size(60,23)
$btnExtraFileByUserComputerDecrypt.Text     = "Decrypt"
$btnExtraFileByUserComputerDecrypt.Enabled  = $True
$btnExtraFileByUserComputerDecrypt.Add_Click({ExtraDecryptFileByUserComputer})
$btnExtraFileByUserComputerDecrypt.Add_MouseHover({$ToolTip.SetToolTip($this,"Decrypt with User and Computer")})
$tabEncryptExtra.Controls.Add($btnExtraFileByUserComputerDecrypt)

$tbxExtraFilePhrase = New-Object System.Windows.Forms.MaskedTextBox
$tbxExtraFilePhrase.PasswordChar = '*'
 $tbxExtraFilePhrase.Location = New-Object System.Drawing.Size(150,320)
 $tbxExtraFilePhrase.Size = New-Object System.Drawing.Size(100,10)
 $tbxExtraFilePhrase.Height = 30
$tbxExtraFilePhrase.Text=""
$tbxExtraFilePhrase.Add_KeyUp({
    if ($_.KeyCode -eq "Enter")
     {
      EncryptButtonLoad
     }
})
$tbxExtraFilePhrase.Add_MouseHover({$ToolTip.SetToolTip($this,"Passphrase to encrypt or decrypt file")})
$tabEncryptExtra.Controls.Add($tbxExtraFilePhrase)

$chkExtraFileByPhrase          = New-Object System.Windows.Forms.CheckBox
$chkExtraFileByPhrase.Location = New-Object System.Drawing.Size(255,320)
$chkExtraFileByPhrase.size     = new-object System.Drawing.Size(150,20)
$chkExtraFileByPhrase.Text     = "Use top phrase"
$chkExtraFileByPhrase.Checked  = $False
$chkExtraFileByPhrase.Add_MouseHover({$ToolTip.SetToolTip($this,"Use phrase from very top")})
$tabEncryptExtra.controls.add($chkExtraFileByPhrase)

$chkExtraSameFile          = New-Object System.Windows.Forms.CheckBox
$chkExtraSameFile.Location = New-Object System.Drawing.Size(410,373)
$chkExtraSameFile.size     = new-object System.Drawing.Size(80,20)
$chkExtraSameFile.Text     = "Same File"
$chkExtraSameFile.Checked  = $False
$chkExtraSameFile.Add_MouseHover({$ToolTip.SetToolTip($this,"Save to and overwrite input file")})
$tabEncryptExtra.controls.add($chkExtraSameFile)

#Execute Related Functions
EncryptCheckboxPasscode
EncryptButtonAdv

$tabEncrypt.Controls.Add($tab1)


###############################################################################
###############################################################################
###############################################################################

$global:TabIndexList=@()
for ($iTab=0; $iTab -lt $tab.TabCount; $iTab++)
 {
  $global:TabIndexList += New-Object PSObject -Property @{
    Status=$tab.TabPages[$iTab].text
    Details=""
    Server="$CurrentComputer"
   }
 }


###############################################################################
### Data tables:
###############################################################################
$Dataset = New-Object System.Data.DataSet

$TblEncryptData = New-Object System.Data.DataTable
$TblEncryptData.TableName = "EncryptData"
[void]$TblEncryptData.Columns.Add("Password")
[void]$TblEncryptData.Columns.Add("UserName")
[void]$TblEncryptData.Columns.Add("Path")
[void]$TblEncryptData.Columns.Add("Version")
[void]$TblEncryptData.Columns.Add("Created")
[void]$TblEncryptData.Columns.Add("Updated")
[void]$TblEncryptData.Columns.Add("Notes")
[void]$TblEncryptData.Columns.Add("HiddenPassword")
$TblEncryptData.Columns["HiddenPassword"].ColumnMapping="Hidden"
$Dataset.tables.add($TblEncryptData)

$TblEncryptHistory = New-Object System.Data.DataTable
$TblEncryptHistory.TableName = "EncryptHistory"
[void]$TblEncryptHistory.Columns.Add("Password")
[void]$TblEncryptHistory.Columns.Add("UserName")
[void]$TblEncryptHistory.Columns.Add("Path")
[void]$TblEncryptHistory.Columns.Add("Version")
[void]$TblEncryptHistory.Columns.Add("Created")
[void]$TblEncryptHistory.Columns.Add("Updated")
[void]$TblEncryptHistory.Columns.Add("Notes")
[void]$TblEncryptHistory.Columns.Add("HiddenPassword")
$TblEncryptHistory.Columns["HiddenPassword"].ColumnMapping="Hidden"
$Dataset.tables.add($TblEncryptHistory)



###############################################################################
### Add the Datagrid View and resize the columns to fit the data
###############################################################################


$dgEncryptData = new-object System.windows.forms.DataGridView
$dgEncryptData.Location = new-object System.Drawing.Size(0,0)
$dgEncryptData.size = new-object System.Drawing.Size(($tab.Width-16),($tab.Height-$tab1.Top-52-$dgEncryptData.Top))#974,415
$dgEncryptData.AutoSizeColumnsMode = "AllCells"
$dgEncryptData.DataSource = $TblEncryptData
$dgEncryptData.Add_CellDoubleClick({EncryptList_DClick})
$dgEncryptData.visible  = $True
$tabEncryptData.Controls.Add($dgEncryptData)

$dgEncryptHistory = new-object System.windows.forms.DataGridView
$dgEncryptHistory.Location = new-object System.Drawing.Size(0,0)
$dgEncryptHistory.size = new-object System.Drawing.Size(($tab.Width-16),($tab.Height-$tab1.Top-52-$dgEncryptHistory.Top))#974,415
$dgEncryptHistory.AutoSizeColumnsMode = "AllCells"
$dgEncryptHistory.DataSource = $TblEncryptHistory
$dgEncryptHistory.Add_CellDoubleClick({EncryptHistory_DClick})
$dgEncryptHistory.visible  = $True
$tabEncryptHistory.Controls.Add($dgEncryptHistory)

###############################################################################
### Status Bar:
###############################################################################
$StatusBar = new-object System.Windows.Forms.StatusBar
$StatusBar_P1 = new-object System.Windows.Forms.StatusBarPanel
$StatusBar_P2 = new-object System.Windows.Forms.StatusBarPanel
$StatusBar_P3 = new-object System.Windows.Forms.StatusBarPanel
$StatusBar_P1.Text = ""
$StatusBar_P1.BorderStyle = "Sunken"
$StatusBar_P1.AutoSize = "Spring"
$StatusBar_P2.Text = ""
$StatusBar_P2.BorderStyle = "Sunken"
$StatusBar_P2.AutoSize = "Spring"
$StatusBar_P3.Text = "$CurrentComputer"
$StatusBar_P3.BorderStyle = "Sunken"
$StatusBar_P3.width = 150
[void]$StatusBar.Panels.Add($StatusBar_P1)
[void]$StatusBar.Panels.Add($StatusBar_P2)
[void]$StatusBar.Panels.Add($StatusBar_P3)
$form.Controls.Add($StatusBar)
$StatusBar.ShowPanels = $true
ClickChangeTab

###############################################################################
### Disable Buttons and Checkboxes:
###############################################################################

###############################################################################
### Draw the GUI:
###############################################################################
$Form.Controls.Add($tab)
$Form.Text = "Password Storage and Encryption Tool - Written By: John Merager"
$Form.size = new-object System.Drawing.Size(($tab.Width+20), ($tab.Height+65))#1010,635
$Form.autoscroll = $true
$Form.topmost = $false
$chkAdvancedAlwaysOnTop.Checked=$Form.topmost
$Form.MaximizeBox = $False
$Form.Add_SizeChanged({FormSizeChanged})
$Form.Add_Shown({$Form.Activate()})

$Ended = $Form.ShowDialog()

Write-host "$Ended"
If ($Ended -eq "Cancel")
{
    write-host "Form Closed"
}

###############################################################################
### END
###############################################################################
<#
#Encrypted.Start:
#Encrypted.End:
#EncryptedHistory.Start:
#EncryptedHistory.End:
#>