Menu Close

Find invalid Base64 characters

Here’s a PowerShell function to find non-base64 characters in a block of text.

Function Find-NonBase64Chars {
    Param(
        [Parameter(Mandatory=$True)]$Text
    )
    $InvalidCharacters = @()
    $x=0
    ForEach ($Line in $Text) { 
        $x++ 
        if ( $Line -notmatch "^[A-Za-z0-9\=\+\/\s\n]+$" ){
            For ($y=0;$y -lt $($Line.Length - 1); $y++) {          
                $Character = $Line[$y]
                If ($Line[$y] -notmatch "^[A-Za-z0-9\=\+\/\s\n]+$"){
                    If ($InvalidCharacters -notcontains $Character) {
                        $InvalidCharacters += $Character
                    }
                    # Write-Output "Invalid Character: Line $x Index $y Character $Character"
                }
            }
        }
    }
    "Invalid Characters:`n$InvalidCharacters"
} 

 4,773 total views,  1 views today

Leave a Reply

Your email address will not be published. Required fields are marked *