Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB.NET
Expertise: Intermediate
Sep 13, 2004

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.
Keyur Kalaria
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap