Guest User

Untitled

a guest
Nov 23rd, 2024
105
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 2.43 KB | Cryptocurrency | 1 0
  1. Add-Type -AssemblyName System.Windows.Forms
  2.  
  3. # Create the Windows Form
  4. $form = New-Object System.Windows.Forms.Form
  5. $form.Text = "Base64 to Hexadecimal Converter"
  6. $form.Size = New-Object System.Drawing.Size(400, 250)
  7. $form.StartPosition = "CenterScreen"
  8.  
  9. # Add a Label
  10. $label = New-Object System.Windows.Forms.Label
  11. $label.Text = "Paste Base64 String:"
  12. $label.AutoSize = $true
  13. $label.Location = New-Object System.Drawing.Point(10, 20)
  14. $form.Controls.Add($label)
  15.  
  16. # Add a TextBox
  17. $textBox = New-Object System.Windows.Forms.TextBox
  18. $textBox.Size = New-Object System.Drawing.Size(360, 20)
  19. $textBox.Location = New-Object System.Drawing.Point(10, 50)
  20. $form.Controls.Add($textBox)
  21.  
  22. # Add a Convert Button
  23. $convertButton = New-Object System.Windows.Forms.Button
  24. $convertButton.Text = "Convert"
  25. $convertButton.Location = New-Object System.Drawing.Point(10, 80)
  26. $form.Controls.Add($convertButton)
  27.  
  28. # Add a TextBox for Hexadecimal Output
  29. $outputBox = New-Object System.Windows.Forms.TextBox
  30. $outputBox.ReadOnly = $true
  31. $outputBox.Multiline = $true
  32. $outputBox.ScrollBars = "Vertical"
  33. $outputBox.Size = New-Object System.Drawing.Size(360, 60)
  34. $outputBox.Location = New-Object System.Drawing.Point(10, 120)
  35. $form.Controls.Add($outputBox)
  36.  
  37. # Add a Copy Button
  38. $copyButton = New-Object System.Windows.Forms.Button
  39. $copyButton.Text = "Copy to Clipboard"
  40. $copyButton.Location = New-Object System.Drawing.Point(100, 80)
  41. $copyButton.Enabled = $false
  42. $form.Controls.Add($copyButton)
  43.  
  44. # Define the Convert button click event
  45. $convertButton.Add_Click({
  46.     try {
  47.         # Get the Base64 string from the TextBox
  48.         $base64String = $textBox.Text
  49.  
  50.         # Convert Base64 to a byte array
  51.         $byteArray = [Convert]::FromBase64String($base64String)
  52.  
  53.         # Convert the byte array to hexadecimal
  54.         $hexString = -join ($byteArray | ForEach-Object { "{0:X2}" -f $_ })
  55.  
  56.         # Display the hexadecimal string in the output TextBox
  57.         $outputBox.Text = $hexString
  58.  
  59.         # Enable the Copy button
  60.         $copyButton.Enabled = $true
  61.     } catch {
  62.         $outputBox.Text = "Error: Invalid Base64 string!"
  63.         $copyButton.Enabled = $false
  64.     }
  65. })
  66.  
  67. # Define the Copy button click event
  68. $copyButton.Add_Click({
  69.     [System.Windows.Forms.Clipboard]::SetText($outputBox.Text)
  70.     [System.Windows.Forms.MessageBox]::Show("Hexadecimal string copied to clipboard!", "Success")
  71. })
  72.  
  73. # Show the form
  74. [void]$form.ShowDialog()
  75.  
Add Comment
Please, Sign In to add comment