문제

Cryptopp을 사용하여 문자열 "ABC"를 인코딩하는데 문제는 인코딩 된 Base64 String이 항상 '0x0A'를 가지고 있습니까? 내 코드는 다음과 같습니다.

#include <iostream>
#include <string>

using namespace std;

#include "crypto/base64.h"
using namespace CryptoPP;

int main() {
string in("abc");

string encoded;

CryptoPP::StringSource ss(
    in,
    true, 
    new CryptoPP::Base64Encoder(
        new CryptoPP::StringSink(encoded)
    )
);

cout << encoded.length() << endl;// outputs 5, should be 4
cout << encoded;
}

"abc"문자열은 "ywjj"로 인코딩되어야하지만 결과는 ywjj n, ( n == 0x0a)이며 길이는 5입니다.

소스 문자열을 변경하는 것은 도움이되지 않습니다. 어떤 문자열도 트레일 링으로 암호화됩니다. 감사

도움이 되었습니까?

해결책

로부터 Base64encoder 문서, 생성자의 서명은 다음과 같습니다

Base64Encoder (BufferedTransformation *attachment=NULL,
               bool insertLineBreaks=true,
               int maxLineLength=72)

따라서 인코딩 된 문자열에서 기본적으로 라인 브레이크를 얻습니다. 이것을 피하기 위해, 그냥하십시오 :

CryptoPP::StringSource ss(
    in,
    true, 
    new CryptoPP::Base64Encoder(
        new CryptoPP::StringSink(encoded),
        false
    )
);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top