Ios Base64 coding and decoding tool and usage, iosbase64
To prevent plaintext transmission of http content, base64 encoding can be used for transmission and decoding by the recipient. This also facilitates binary data string transmission.
For ios, google provides a good tool class to facilitate base64 encoding and decoding. Of course, openssl can also be used.
It is troublesome. Google provides three files.
The official website address is:
Http://code.google.com/p/google-toolbox-for-mac/
There are a lot of babies here. If you find it difficult to find these three files, I will add them to the attachment. Decompress the package and put it in the ios project.
Usage:
Check that the GTMBase64.h header file contains detailed function descriptions. Here we only give two examples:
1. encoding, that is, base64 encryption:
Function:
// DecodeData:
//
/// Base64 decodes contents of the NSData object.
//
/// Returns:
/// A new autoreleased NSData with the decoded payload. nil for any error.
//
+ (NSData *) decodeData :( NSData *) data;
Example:
NSString * input = @ "Hello World ";
NSData * data = [input dataUsingEncoding: NSUTF8StringEncoding allowLossyConversion: YES];
Data = [GTMBase64 encodeData: data];
NSString * base64String = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@ "base64String = % @", base64String );
If it succeeds, the encrypted data is printed: SGVsbG8sIFdvcmxk
In this way, the data can be transmitted from http.
2. decoding, that is, base64 decryption:
The function is used here:
// DecodeString:
//
/// Base64 decodes contents of the NSString.
//
/// Returns:
/// A new autoreleased NSData with the decoded payload. nil for any error.
//
+ (NSData *) decodeString :( NSString *) string;
The usage is as follows:
NSData * data = [GTMBase64 decodeString: @ "SGVsbG8sIFdvcmxk"];
In this way, the original NSString type is parsed into NSData data. You can use
NSLog (@ "data = % @", data );
Output: log outputs hexadecimal values, for example:
Base64Test [5670: c07] data = <01000a6e 735f766f 645f3030 3102005c 81705900 00000000 08619971 005c8020 0101124c 803a0001 18beee29 11aef543 116037969ad 50e57f2c>
If you output data with the NSString type, the content isHello, World
What is Linux C base64 encoding/decoding used in? (Pass by, too)
1. Base64 encoding can be used to transmit long identification information in the HTTP environment.
2. Base64 encoding/decoding is also used during encryption/decryption. For example, functions encapsulated with EVP in Openssl, EVP_EncodeInit, EVP_EncodeUpdate, EVP_EncodeFinal, etc.
3. Thunder is also generated by base64 encoding.
Hope to help you.
How can I transmit base64 encoding with ASCII code ?? For example: base64 encoding: z (lower case) I E 6 is sent in ASCII Code as follows :??
Conversion representation. In this way, the content can be encrypted. Encryption is mainly used in the HTTP environment. To put it simply, for example, converting ABC into SDK. In this way, you will not understand the content.