diff -r 85266cc22c7f -r 35baca0e7a2e javacommons/utils/src/javacommonutils.cpp --- a/javacommons/utils/src/javacommonutils.cpp Fri Jun 11 13:33:44 2010 +0300 +++ b/javacommons/utils/src/javacommonutils.cpp Tue Jul 06 20:36:19 2010 +0300 @@ -277,6 +277,34 @@ return result; } +OS_EXPORT std::wstring JavaCommonUtils::wbase64encode(const std::wstring& aData) +{ + BIO* b64 = BIO_new(BIO_f_base64()); + if (NULL == b64) + { + return L""; + } + BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); + BIO* bmem = BIO_new(BIO_s_mem()); + + b64 = BIO_push(b64, bmem); + BIO_write(b64, aData.c_str(), aData.length() * 2); + BIO_flush(b64); + + BUF_MEM* bptr; + BIO_get_mem_ptr(b64, &bptr); + + std::wstring result; + // convert each char to wchar + for (int i = 0; i < bptr->length; i++) + { + result.push_back((wchar_t)*(bptr->data + i)); + } + BIO_free_all(b64); + + return result; +} + OS_EXPORT std::string JavaCommonUtils::base64decode(const std::string& aData) { BIO* b64 = BIO_new(BIO_f_base64());