Determine Whether a String is a base64encoded

Determine Whether a String is a base64encoded

This function returns TRUE if the string is a base64encoded. Otherwise, it returns FALSE.

'AUTHOR: KEYUR KALARIA'DATE: JULY 24, 2004'VERY USEFUL FUNCTION AND COULD BE HANDY IF YOUR WORKING AROUND ENCRYPTING OR DECRYPTING DATA'PASS THE STRING WHICH YOU WANT TO VERIFY, THE FUNCTION WILL RETURN TRUE IF THE STRING IS A BASE64ENCODED OR WILL RETURN FALSE.Public Shared Function IsBase64String(ByVal s As String) As Boolean	Dim baTemp() As Byte        Try            baTemp = Convert.FromBase64String(s)        Catch ex As FormatException            Return False        Catch ex As ArgumentNullException            Return False        End Try        Return Convert.ToBase64String(baTemp).Equals(s)End Function

Note: This will happily return true for anything that *could* be a base-64 encoded string, but may simply be nonsense characters.


Share the Post: