javacommons/utils/src/javacommonutils.cpp
changeset 49 35baca0e7a2e
parent 21 2a9601315dfc
child 57 59b3b4473dc8
equal deleted inserted replaced
35:85266cc22c7f 49:35baca0e7a2e
   275     BIO_free_all(b64);
   275     BIO_free_all(b64);
   276 
   276 
   277     return result;
   277     return result;
   278 }
   278 }
   279 
   279 
       
   280 OS_EXPORT std::wstring JavaCommonUtils::wbase64encode(const std::wstring& aData)
       
   281 {
       
   282     BIO* b64  = BIO_new(BIO_f_base64());
       
   283     if (NULL == b64)
       
   284     {
       
   285         return L"";
       
   286     }
       
   287     BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
       
   288     BIO* bmem = BIO_new(BIO_s_mem());
       
   289 
       
   290     b64 = BIO_push(b64, bmem);
       
   291     BIO_write(b64, aData.c_str(), aData.length() * 2);
       
   292     BIO_flush(b64);
       
   293 
       
   294     BUF_MEM* bptr;
       
   295     BIO_get_mem_ptr(b64, &bptr);
       
   296 
       
   297     std::wstring result;
       
   298     // convert each char to wchar
       
   299     for (int i = 0; i < bptr->length; i++)
       
   300     {
       
   301         result.push_back((wchar_t)*(bptr->data + i));
       
   302     }
       
   303     BIO_free_all(b64);
       
   304 
       
   305     return result;
       
   306 }
       
   307 
   280 OS_EXPORT std::string JavaCommonUtils::base64decode(const std::string& aData)
   308 OS_EXPORT std::string JavaCommonUtils::base64decode(const std::string& aData)
   281 {
   309 {
   282     BIO* b64  = BIO_new(BIO_f_base64());
   310     BIO* b64  = BIO_new(BIO_f_base64());
   283     if (NULL == b64)
   311     if (NULL == b64)
   284     {
   312     {