Index: /trunk/include/VBox/com/string.h
===================================================================
--- /trunk/include/VBox/com/string.h	(revision 84286)
+++ /trunk/include/VBox/com/string.h	(revision 84287)
@@ -661,4 +661,18 @@
 
 
+    /** @name BASE64 related methods
+     * @{ */
+    /**
+     * Encodes the give data as BASE64.
+     *
+     * @returns S_OK or E_OUTOFMEMORY.
+     * @param   pvData          Pointer to the data to encode.
+     * @param   cbData          Number of bytes to encode.
+     * @param   fLineBreaks     Whether to add line breaks (true) or just encode it
+     *                          as a continuous string.
+     */
+    HRESULT base64Encode(const void *pvData, size_t cbData, bool fLineBreaks = false);
+    /** @} */
+
 #if defined(VBOX_WITH_XPCOM)
     /**
Index: /trunk/src/VBox/Main/glue/string.cpp
===================================================================
--- /trunk/src/VBox/Main/glue/string.cpp	(revision 84286)
+++ /trunk/src/VBox/Main/glue/string.cpp	(revision 84287)
@@ -18,7 +18,8 @@
 #include "VBox/com/string.h"
 
+#include <iprt/base64.h>
 #include <iprt/err.h>
+#include <iprt/log.h>
 #include <iprt/path.h>
-#include <iprt/log.h>
 #include <iprt/string.h>
 #include <iprt/uni.h>
@@ -228,4 +229,18 @@
         return ucLeft < ucRight ? -1 : 1;
     }
+}
+
+HRESULT Bstr::base64Encode(const void *pvData, size_t cbData, bool fLineBreaks /*= false*/)
+{
+    uint32_t const fFlags     = fLineBreaks ? RTBASE64_FLAGS_EOL_LF : RTBASE64_FLAGS_NO_LINE_BREAKS;
+    size_t         cwcEncoded = RTBase64EncodedUtf16LengthEx(cbData, fFlags);
+    HRESULT hrc = reserveNoThrow(cwcEncoded + 1);
+    if (SUCCEEDED(hrc))
+    {
+        int vrc = RTBase64EncodeUtf16Ex(pvData, cbData, fFlags, mutableRaw(), cwcEncoded, &cwcEncoded);
+        AssertRCReturnStmt(vrc, setNull(), E_FAIL);
+        hrc = joltNoThrow(cwcEncoded);
+    }
+    return hrc;
 }
 
