質問

ワイドストリングをBase64に変換する最善の方法は何ですか?

役に立ちましたか?

解決

オクテット(8ビットシンボル) - > BASS64(6ビットシンボル)変換は文字ではなくバイトで機能しますので、文字列エンコーディングとは同じように機能します。


をクリアする:base64は文字符号化ではありません。送信者と受信者は、トランスポート方法(Base64、GZIPなど)だけでなく、文字エンコード(ASCII、UTF-8、UTF-16、UCS-2など)に同意する必要があります。

他のヒント

Base64にデータを符号化するには、 base64 Xercesライブラリからのクラス。次のようになります。

std::wstring input_string = SOME; // some wide string
// keep it in contiguous memory (the following string is not needed in C++0x)
std::vector<wchar_t> raw_str( input_string.begin(), input_string.end() );

XMLSize_t len;
XMLByte* data_encoded = xercesc::Base64::encode( reinterpret_cast<const XMLByte*>(&raw_str[0]), raw_str.size()*sizeof(wchar_t), &len );
XMLCh* text_encoded = xercesc::XMLString::transcode( reinterpret_cast<char*>(data_encoded) );

// here's text_encoded is encoded text
// do some with text_encoded

XMLString::release( &text_encoded );
XMLString::release( reinterpret_cast<char**>(&data_encoded) );
.

MFCでVisual C ++を使用している場合は、これを行うためのライブラリがあります。Base64EncodeBase64Decodeをチェックしてください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top