You can use it as follows:
<img alt="Embedded Image" src="data:image/png;base64,{base64 encoding}" />
It is used to create new images or to store images in plain text. You can learn more about base64 encoding here on Wikipedia: http://nl.wikipedia.org/wiki/Base64
How it works?
- Symbols are converted to binair
- They take a group of 6 bits
- Groups will be converted to decimal
- For each decimal number, they take a number at position n + 1, which is in the base64 character table, numbers range from 0 to 63.
This does not always work out correctly, since the number of bits must be a multiple of 6. If this is the case, then depending on the required number of additional bits, 2 or 4 zeros will be inserted at the end, If so, = will be added at the end.
Base64 Character Table
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
Different languages ββand uses
Php
<?php base64_encode($source);
Python
>>> import base64 >>> encoded = base64.b64encode('data to be encoded') >>> encoded 'ZGF0YSB0byBiZSBlbmNvZGVk' >>> data = base64.b64decode(encoded) >>> data 'data to be encoded'
Goal c
// Encoding NSData *plainData = [plainString dataUsingEncoding:NSUTF8StringEncoding]; NSString *base64String = [plainData base64EncodedStringWithOptions:0]; NSLog(@"%@", base64String); // Zm9v // Decoding NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:base64String options:0]; NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding]; NSLog(@"%@", decodedString); // foo
source share