Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add-Type -AssemblyName System.Windows.Forms
- # Create the Windows Form
- $form = New-Object System.Windows.Forms.Form
- $form.Text = "Base64 to Hexadecimal Converter"
- $form.Size = New-Object System.Drawing.Size(400, 250)
- $form.StartPosition = "CenterScreen"
- # Add a Label
- $label = New-Object System.Windows.Forms.Label
- $label.Text = "Paste Base64 String:"
- $label.AutoSize = $true
- $label.Location = New-Object System.Drawing.Point(10, 20)
- $form.Controls.Add($label)
- # Add a TextBox
- $textBox = New-Object System.Windows.Forms.TextBox
- $textBox.Size = New-Object System.Drawing.Size(360, 20)
- $textBox.Location = New-Object System.Drawing.Point(10, 50)
- $form.Controls.Add($textBox)
- # Add a Convert Button
- $convertButton = New-Object System.Windows.Forms.Button
- $convertButton.Text = "Convert"
- $convertButton.Location = New-Object System.Drawing.Point(10, 80)
- $form.Controls.Add($convertButton)
- # Add a TextBox for Hexadecimal Output
- $outputBox = New-Object System.Windows.Forms.TextBox
- $outputBox.ReadOnly = $true
- $outputBox.Multiline = $true
- $outputBox.ScrollBars = "Vertical"
- $outputBox.Size = New-Object System.Drawing.Size(360, 60)
- $outputBox.Location = New-Object System.Drawing.Point(10, 120)
- $form.Controls.Add($outputBox)
- # Add a Copy Button
- $copyButton = New-Object System.Windows.Forms.Button
- $copyButton.Text = "Copy to Clipboard"
- $copyButton.Location = New-Object System.Drawing.Point(100, 80)
- $copyButton.Enabled = $false
- $form.Controls.Add($copyButton)
- # Define the Convert button click event
- $convertButton.Add_Click({
- try {
- # Get the Base64 string from the TextBox
- $base64String = $textBox.Text
- # Convert Base64 to a byte array
- $byteArray = [Convert]::FromBase64String($base64String)
- # Convert the byte array to hexadecimal
- $hexString = -join ($byteArray | ForEach-Object { "{0:X2}" -f $_ })
- # Display the hexadecimal string in the output TextBox
- $outputBox.Text = $hexString
- # Enable the Copy button
- $copyButton.Enabled = $true
- } catch {
- $outputBox.Text = "Error: Invalid Base64 string!"
- $copyButton.Enabled = $false
- }
- })
- # Define the Copy button click event
- $copyButton.Add_Click({
- [System.Windows.Forms.Clipboard]::SetText($outputBox.Text)
- [System.Windows.Forms.MessageBox]::Show("Hexadecimal string copied to clipboard!", "Success")
- })
- # Show the form
- [void]$form.ShowDialog()
Add Comment
Please, Sign In to add comment