first commit
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
|
||||
## Description
|
||||
|
||||
This function Encodes AND Decodes a File OR String
|
||||
|
||||
## The Function
|
||||
|
||||
### [B64]
|
||||
|
||||
This funtion takes 1 parameter with 4 versions:
|
||||
|
||||
[encFile] - encode file
|
||||
|
||||
[encString] - encode string
|
||||
|
||||
[decFile] - decode file
|
||||
|
||||
[decString] - decode string
|
||||
|
||||
***
|
||||
|
||||
## [SYNTAX]
|
||||
|
||||
### Encode a File
|
||||
|
||||
`B64 -encFile "C:\Users\User\Desktop\example.txt"`
|
||||
|
||||
### Decode a File
|
||||
|
||||
`B64 -decFile "C:\Users\User\Desktop\example.txt"`
|
||||
|
||||
WARNING! When working with strings you have to wrap it in SINGLE QUOTES!
|
||||
|
||||
### Encode a String
|
||||
|
||||
`B64 -encString 'start notepad'`
|
||||
|
||||
### Decode a String
|
||||
|
||||
`B64 -decString 'cwB0AGEAcgB0ACAAbgBvAHQAZQBwAGEAZAA='`
|
||||
|
||||
### Copy out-put directly to clipboard with the following syntax:
|
||||
|
||||
COMMAND | clip
|
||||
|
||||
***
|
||||
|
||||
```PowerShell
|
||||
function B64 {
|
||||
[CmdletBinding(DefaultParameterSetName="encFile")]
|
||||
param(
|
||||
[Parameter(Position=0, ParameterSetName="encFile")]
|
||||
[Alias("ef")]
|
||||
[string]$encFile,
|
||||
|
||||
[Parameter(Position=0, ParameterSetName="encString")]
|
||||
[Alias("es")]
|
||||
[string]$encString,
|
||||
|
||||
[Parameter(Position=0, ParameterSetName="decFile")]
|
||||
[Alias("df")]
|
||||
[string]$decFile,
|
||||
|
||||
[Parameter(Position=0, ParameterSetName="decString")]
|
||||
[Alias("ds")]
|
||||
[string]$decString
|
||||
|
||||
)
|
||||
|
||||
if ($psCmdlet.ParameterSetName -eq "encFile") {
|
||||
$encoded = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes((Get-Content -Path $encFile -Raw -Encoding UTF8)))
|
||||
return $encoded
|
||||
}
|
||||
|
||||
elseif ($psCmdlet.ParameterSetName -eq "encString") {
|
||||
$encoded = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($encString))
|
||||
return $encoded
|
||||
}
|
||||
|
||||
elseif ($psCmdlet.ParameterSetName -eq "decFile") {
|
||||
$data = Get-Content $decFile
|
||||
$decoded = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($data))
|
||||
return $decoded
|
||||
}
|
||||
|
||||
elseif ($psCmdlet.ParameterSetName -eq "decString") {
|
||||
$decoded = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($decString))
|
||||
return $decoded
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user