Base 64 인코딩은 무엇에 사용됩니까?
사람들이 여기저기서 "베이스 64 인코딩"에 대해 이야기하는 것을 들었습니다. 그것은 무엇을 위해 사용됩니까?
네트워크를 통해 전송하려는 이진 데이터가있을 때 일반적으로 원시 형식으로 유선을 통해 비트와 바이트를 스트리밍하는 방식으로 수행하지 않습니다. 왜? 일부 미디어는 스트리밍 텍스트 용으로 만들어 졌기 때문입니다. 알 수 없습니다. 일부 프로토콜은 이진 데이터를 제어 문자 (예 : 모뎀)로 해석하거나 기본 프로토콜이 특수 문자 조합을 입력했다고 생각할 수 있기 때문에 이진 데이터가 망가질 수 있습니다 (예 : FTP가 줄을 변환하는 방법). 엔딩).
따라서이 문제를 해결하기 위해 사람들은 이진 데이터를 문자로 인코딩합니다. Base64는 이러한 유형의 인코딩 중 하나입니다.
왜 64일까요?
일반적으로 많은 문자 집합에있는 동일한 64 개의 문자에 의존 할 수 있기 때문에 데이터가 손상되지 않고 다른 쪽에서 끝날 것이라고 합리적으로 확신 할 수 있습니다.
기본적으로 임의의 바이너리 데이터를 ASCII 텍스트로 인코딩하는 방법입니다. 3 바이트의 데이터 당 4 개의 문자와 끝 부분에 약간의 패딩이 필요합니다.
기본적으로 입력의 각 6 비트는 64 자 알파벳으로 인코딩됩니다. "표준"알파벳은 AZ, az, 0-9 및 + 및 /를 사용하며 =는 패딩 문자로 사용됩니다. URL에 안전한 변형이 있습니다.
Wikipedia 는 더 많은 정보를 얻을 수있는 합리적으로 좋은 소스입니다.
Base-64 인코딩은 이진 데이터를 텍스트로 변환하여 전자 메일 및 HTML 양식 데이터와 같은 항목으로 더 쉽게 전송할 수있는 방법입니다.
http://en.wikipedia.org/wiki/Base64
결과 텍스트에 문자, 숫자 및 기호 "+", "/"및 "="만있는 이진 데이터의 텍스트 인코딩입니다. 텍스트 데이터에 특별히 사용되는 미디어를 통해 바이너리 데이터를 저장 / 전송하는 편리한 방법입니다.
그런데 왜 Base-64일까요? 바이너리 데이터를 즉시 떠오르는 텍스트로 변환하는 두 가지 대안은 다음과 같습니다.
- Decimal : 각 바이트의 10 진수 값을 3 개의 숫자로 저장합니다 : 045 112 101 037 등. 여기서 각 바이트는 3 바이트로 표시됩니다. 데이터는 3 배로 팽창합니다.
- 16 진수 : 바이트를 16 진수 쌍으로 저장합니다. AC 47 0D 1A 등 여기서 각 바이트는 2 바이트로 표시됩니다. 데이터는 두 배로 팽창합니다.
Base-64는 6 비트 (6 x 4 = 24 비트)에 걸쳐있는 4 개의 문자로 3 바이트 (8 x 3 = 24 비트)를 매핑합니다. 결과는 "TWFuIGlzIGRpc3Rpb ..."와 유사합니다. 따라서 팽만감은 원래의 4/3 = 1.3333333 배에 불과합니다.
이미 말한 것 외에도 나열되지 않은 두 가지 매우 일반적인 용도는 다음과 같습니다.
해시 :
해시는 바이트 블록을 128 비트 또는 256 비트 (SHA / MD5)와 같은 고정 크기의 다른 바이트 블록으로 변환하는 단방향 함수입니다. 결과 바이트를 Base64로 변환하면 특히 무결성 체크섬을 비교할 때 해시를 훨씬 쉽게 표시 할 수 있습니다. 해시는 Base64에서 자주 볼 수 있으므로 많은 사람들이 Base64 자체를 해시로 착각합니다.
암호화 :
암호화 키는 텍스트 일 필요는 없지만 원시 바이트 일 필요가 있기 때문에 파일이나 데이터베이스에 저장해야하는 경우도 있는데, Base64가 유용합니다. 결과적으로 암호화 된 바이트와 동일합니다.
Base64가 암호화에 자주 사용되지만 보안 메커니즘은 아닙니다. 누구나 Base64 문자열을 원래 바이트로 다시 변환 할 수 있으므로 데이터를 보호하는 수단으로 사용해서는 안되며 원시 바이트를 더 쉽게 표시하거나 저장하는 형식으로 만 사용해야합니다.
인증서
PEM 형식의 x509 인증서는 Base 64로 인코딩됩니다. http://how2ssl.com/articles/working_with_pem_files/
에서 http://en.wikipedia.org/wiki/Base64
Base64라는 용어는 특정 MIME 콘텐츠 전송 인코딩을 나타냅니다. 또한 이진 데이터를 수치 적으로 처리하고 기본 64 표현으로 변환하여 이진 데이터를 인코딩하는 유사한 인코딩 체계에 대한 일반적인 용어로 사용됩니다. 특정 기본 선택은 문자 집합 인코딩의 역사 때문입니다. 대부분의 인코딩에 공통적 인 부분 집합의 일부이며 인쇄 가능한 64 자 집합을 선택할 수 있습니다. 이러한 조합으로 인해 기존에는 8 비트 클린이 아니었던 이메일과 같은 시스템을 통해 전송 중에 데이터가 수정 될 가능성이 거의 없습니다.
Base64는 다음과 같은 다양한 컨텍스트에서 사용할 수 있습니다.
- Evolution과 Thunderbird는 Base64를 사용하여 이메일 암호를 난독 화합니다 [1]
- Base64를 사용하여 구분 기호 충돌을 유발할 수있는 텍스트를 전송하고 저장할 수 있습니다.
Base64는 종종 암호화 키 관리의 오버 헤드없이 비밀을 모호하게하는 빠르고 안전하지 않은 지름길로 사용됩니다.
스팸 발송자는 Base64를 사용하여 기본 스팸 방지 도구를 회피합니다.이 도구는 종종 Base64를 디코딩하지 않으므로 인코딩 된 메시지에서 키워드를 감지 할 수 없습니다.
- Base64는 LDIF 파일의 문자열을 인코딩하는 데 사용됩니다.
- Base64는 때때로 Firefox의 bookmarks.html과 유사한 구문을 사용하여 XML 파일에 바이너리 데이터를 포함하는 데 사용됩니다.
- Base64는 또한 정부 재정 서명 인쇄 장치 (일반적으로 직렬 또는 병렬 포트를 통해)와 통신 할 때 사용되어 서명을 위해 영수증 문자를 전송할 때 지연을 최소화합니다.
- Base64는 외부 파일에 의존하지 않도록 스크립트 내의 이미지와 같은 이진 파일을 인코딩하는 데 사용됩니다.
- 원시 이미지 데이터를 background-image와 같은 CSS 속성에 포함하는 데 사용할 수 있습니다.
In the early days of computers, when telephone line inter-system communication was not particularly reliable, a quick & dirty method of verifying data integrity was used: "bit parity". In this method, every byte transmitted would have 7-bits of data, and the 8th would be 1 or 0, to force the total number of 1 bits in the byte to be even.
Hence 0x01 would be transmited as 0x81; 0x02 would be 0x82; 0x03 would remain 0x03 etc.
To further this system, when the ASCII character set was defined, only 00-7F were assigned characters. (Still today, all characters set in the range 80-FF are non-standard)
Many routers of the day put the parity check and byte translation into hardware, forcing the computers attached to them to deal strictly with 7-bit data. This force email attachments (and all other data, which is why HTTP & SMTP protocols are text-based), to be convert into a text-only format.
Few of the routers survived into the 90s. I severely doubt any of them are in use today.
Some transportation protocols only allow alphanumerical characters to be transmitted. Just imagine a situation where control characters are used to trigger special actions and/or that only supports a limited bit width per character. Base64 transforms any input into an encoding that only uses alphanumeric characters, +, / and the = as a padding character.
The usage of Base64 I'm going to describe here is somewhat a hack. So if you don't like hacks, please do not go on.
I went into trouble when I discovered that MySQL's utf8 does not support 4-byte unicode characters since it uses a 3-byte version of utf8. So what I did to support full 4-byte unicode over MySQL's utf8? Well, base64 encode strings when storing into the database and base64 decode when retrieving.
Since base64 encoding and decoding is very fast, the above worked perfectly.
You have the following points to take note of:
Base64 encoding uses 33% more storage
Strings stored in the database wont be human readable (You could sell that as a feature that database strings use a basic form of encryption).
You could use the above method for any storage engine that does not support unicode.
Years ago, when mailing functionality was introduced, so that was utterly text based, as the time passed, need for attachments like image and media (audio,video etc) came into existence. When these attachments are sent over internet (which is basically in the form of binary data), the probability of binary data getting corrupt is high in its raw form. So, to tackle this problem BASE64 came along.
The problem with binary data is that it contains null characters which in some languages like C,C++ represent end of character string so sending binary data in raw form containing NULL bytes will stop a file from being fully read and lead in a corrupt data.
For Example :
In C and C++, this "null" character shows the end of a string. So "HELLO" is stored like this:
H E L L O
72 69 76 76 79 00
The 00 says "stop here".
Now let’s dive into how BASE64 encoding works.
Point to be noted : Length of the string should be in multiple of 3.
Example 1 :
String to be encoded : “ace”, Length=3
1) Convert each character to decimal.
a= 97, c= 99, e= 101
2) Change each decimal to 8-bit binary representation.
97= 01100001, 99= 01100011, 101= 01100101
Combined : 01100001 01100011 01100101
3) Seperate in a group of 6-bit.
011000 010110 001101 100101
4) Calculate binary to decimal
011000= 24, 010110= 22, 001101= 13, 100101= 37
5) Covert decimal characters to base64 using base64 chart.
24= Y, 22= W, 13= N, 37= l
“ace” => “YWNl”
Example 2 :
String to be encoded : “abcd” Length=4, it's not multiple of 3. So to make string length multiple of 3 , we must add 2 bit padding to make length= 6. Padding bit is represented by “=” sign.
Point to be noted : One padding bit equals two zeroes 00 so two padding bit equals four zeroes 0000.
So lets start the process :–
1) Convert each character to decimal.
a= 97, b= 98, c= 99, d= 100
2) Change each decimal to 8-bit binary representation.
97= 01100001, 98= 01100010, 99= 01100011, 100= 01100100
3) Separate in a group of 6-bit.
011000, 010110, 001001, 100011, 011001, 00
so the last 6-bit is not complete so we insert two padding bit which equals four zeroes “0000”.
011000, 010110, 001001, 100011, 011001, 000000 ==
Now, it is equal. Two equals sign at the end show that 4 zeroes were added (helps in decoding).
4) Calculate binary to decimal.
011000= 24, 010110= 22, 001001= 9, 100011= 35, 011001= 25, 000000=0 ==
5) Covert decimal characters to base64 using base64 chart.
24= Y, 22= W, 9= j, 35= j, 25= Z, 0= A ==
“abcd” => “YWJjZA==”
It's used for converting arbitrary binary data to ASCII text.
For example, e-mail attachments are sent this way.
I use it in a practical sense when we transfer large binary objects (images) via web services. So when I am testing a C# web service using a python script, the binary object can be recreated with a little magic.
[In python]
import base64
imageAsBytes = base64.b64decode( dataFromWS )
“Base64 encoding schemes are commonly used when there is a need to encode binary data that needs be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remains intact without modification during transport”(Wiki, 2017)
Example could be the following: you have a web service that accept only ASCII chars. You want to save and then transfer user’s data to some other location (API) but recipient want receive untouched data. Base64 is for that. . . The only downside is that base64 encoding will require around 33% more space than regular strings.
Another Example:: uenc = url encoded = aHR0cDovL2xvYy5tYWdlbnRvLmNvbS9hc2ljcy1tZW4tcy1nZWwta2F5YW5vLXhpaS5odG1s = http://loc.querytip.com/asics-men-s-gel-kayano-xii.html.
As you can see we can’t put char “/” in URL if we want to send last visited URL as parameter because we would break attribute/value rule for “MOD rewrite” – GET parameter.
A full example would be: “http://loc.querytip.com/checkout/cart/add/uenc/http://loc.magento.com/asics-men-s-gel-kayano-xii.html/product/93/”
Mostly, I've seen it used to encode binary data in contexts that can only handle ascii - or a simple - character sets.
To expand a bit on what Brad is saying: many transport mechanisms for email and Usenet and other ways of moving data are not "8 bit clean", which means that characters outside the standard ascii character set might be mangled in transit - for instance, 0x0D might be seen as a carriage return, and turned into a carriage return and line feed. Base 64 maps all the binary characters into several standard ascii letters and numbers and punctuation so they won't be mangled this way.
Base64
Base64 is a generic term for a number of similar encoding schemes that encode binary data by treating it numerically and translating it into a base 64 representation. The Base64 term originates from a specific MIME content transfer encoding.
Base64 encoding schemes are commonly used when there is a need to encode binary data that needs be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remains intact without modification during transport. Base64 is used commonly in a number of applications including email via MIME, and storing complex data in XML.
Base64 can be used for many purposes.
The primary reason is to convert binary data to something passable.
I sometimes use it to pass JSON data around from one site to another, store information in cookies about a user.
Note: You "can" use it for encryption - I don't see why people say you can't, and that it's not encryption, although it would be easily breakable and is frowned upon. Encryption means nothing more than converting one string of data to another string of data that can be either later decrypted or not, and that's what base64 does.
참고URL : https://stackoverflow.com/questions/201479/what-is-base-64-encoding-used-for
'Programing' 카테고리의 다른 글
| HttpClient 요청에 대한 Content-Type 헤더를 어떻게 설정합니까? (0) | 2020.10.02 |
|---|---|
| Java에서 기존 파일에 텍스트를 추가하는 방법 (0) | 2020.10.02 |
| : not () 의사 클래스가 여러 인수를 가질 수 있습니까? (0) | 2020.09.30 |
| Spring Boot 애플리케이션 용 포트를 구성하는 방법 (0) | 2020.09.30 |
| Bootstrap 3에서 SR 전용이란 무엇입니까? (0) | 2020.09.30 |

