시중에 돌아다니는 base64관련 함수를 짜집기 한겁니다. 출처는 PHP3 에 들어간 Base64 Encode & Decode Source 랍니다.
목적으로 하는 문자열을 입력하면 base64로 인코딩과 디코딩을 시켜줍니다. base64는
웹에서 데이터를 전달(Content-Transfer)하기 위한 목적으로 사용됩니다. 사람이 읽을 수 없는 (바이너리)데이터의 경우 내용과 형태가 멋대로인 경우가 많아서 이 상태 그대로는 HTTP프로토콜을 이용해서 전달하기가 애매모호한데, 이것을 일관성 있는 데이터로 바꿔줍니다. base64인코딩을 할경우 US-ASCII에서 이용하는 65개의 pritable 문자로 데이터를 재구성합니다.
인코딩와 디코딩에 사용되는 알고리즘이 간단하다는 장점이 있지만 데이터를 인코딩할경우 원래 데이터에 비해서 33%정도 크기가 커진다는 단점이 존재 합니다.
<!> 이 함수는 완전하지 않은 버젼입니다. 내부에서 malloc()를 한후 free()하는 과정이 없으므로 메모리 누수가 발생할 수 있습니다. 약간 수정을 해야 될것 같은데, 일단은 그냥 올립니다.
사용방법
unsigned char *__base64_encode(const unsigned char *str,
int length, int *ret_length);
unsigned char *__base64_decode(const unsigned char *str,
int length, int *ret_length);
base64 는 0~255 사이의 문자값을 각각 0~63의 64단계의 문자값만을 사용하여 변환하는 과정을 말하며 2글자가 3글자로 늘어납니다. 이것이 주로 사용되는 이유는 문자열 사이에 공백을 넣어서는 안될경우와 멀티바이트를 사용하지 않아야 할 결우에 많이들 사용합니다. 공백을 넣지 않아야 하는 경우는 대부분 token 이 공백으로 분류될때가 되겠지요. - [minzkn]
설명
사용방법
코드
또다른 버젼
변경사항
Recent Posts
Archive Posts
Tags