### Basic Decode and Encode

Example Subs for Encoding and Decoding A String
Reference: http://docs.oracle.com/javase/8/docs/api/java/util/Base64.html
Encode
Reference: http://docs.oracle.com/javase/8/docs/api/java/util/Base64.Encoder.html
'Encode a string using Base64 Encoding
'Parameter Plain String without any special characters
'Return Encoded String
`Sub EncodeString(s As String) As String
Dim joEncoder As JavaObject
Return joEncoder.InitializeStatic("java.util.Base64").RunMethodJO("getEncoder",Null).RunMethod("encodeToString", Array(s.GetBytes("UTF8")))
End Sub`
Decode
Reference: http://docs.oracle.com/javase/8/docs/api/java/util/Base64.Decoder.html
'Decode an encoded string using Base64 Decoding
'Parameter Encoded String
'Return Decoded String
`Sub DecodeString(strencoded As String) As String
Dim joDecoder As JavaObject
Dim joDecodedString As JavaObject = joDecoder.InitializeStatic("java.util.Base64").RunMethodJO("getDecoder",Null).RunMethod("decode", Array(strencoded))
Return joDecodedString.InitializeNewInstance("java.lang.String",Array(joDecodedString, "utf-8")).RunMethod("toString", Null)
End Sub`
Example
lblMessage1.Text = EncodeMimeString("HelloWorld")
Output:SGVsbG9Xb3JsZA==
lblMessage2.Text = DecodeMimeString(lblMessage1.Text )
Output:HelloWorld

Changed: , Category: Strings Decode and Encode, File: T6C256M1863.htm, ID: 1863