문제

넓은 문자열을 Base64로 변환하는 가장 좋은 방법은 무엇입니까?

도움이 되었습니까?

해결책

옥텟 (8 비트 심볼) -> Base64 (6 비트 심볼) 변환은 문자열 인코딩과 독립적으로 동일한 방식으로 작동하므로 바이트에서 작동합니다.


지우기 : Base64는 문자 인코딩이 아닙니다.보낸 사람과 수신자는 문자 인코딩 (ASCII, UTF-8, UTF-16, UCS-2 등)과 전송 방법 (Base64, Gzip 등)에 동의해야합니다.

다른 팁

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