FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
NSData(TSXAdditions) Category Reference

Instance Methods

(NSString *) - hexadecimalString
 
(NSString *) - base64EncodedString
 

Detailed Description

Definition at line 31 of file TSXAdditions.h.

Method Documentation

◆ base64EncodedString

- (NSString *) base64EncodedString

Definition at line 1 of file TSXAdditions.m.

213{
214 // Construct an OpenSSL context
215 BIO *context = BIO_new(BIO_s_mem());
216
217 // Tell the context to encode base64
218 BIO *command = BIO_new(BIO_f_base64());
219 context = BIO_push(command, context);
220 BIO_set_flags(context, BIO_FLAGS_BASE64_NO_NL);
221
222 // Encode all the data
223 ERR_clear_error();
224 BIO_write(context, [self bytes], [self length]);
225 (void)BIO_flush(context);
226
227 // Get the data out of the context
228 char *outputBuffer;
229 long outputLength = BIO_get_mem_data(context, &outputBuffer);
230 NSString *encodedString = [[NSString alloc] initWithBytes:outputBuffer
231 length:outputLength
232 encoding:NSASCIIStringEncoding];
233
234 BIO_free_all(context);
235
236 return encodedString;
237}

◆ hexadecimalString

- (NSString *) hexadecimalString

Definition at line 1 of file TSXAdditions.m.

194{
195 /* Returns hexadecimal string of NSData. Empty string if data is empty. */
196
197 const unsigned char *dataBuffer = (const unsigned char *)[self bytes];
198
199 if (!dataBuffer)
200 return [NSString string];
201
202 NSUInteger dataLength = [self length];
203 NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
204
205 for (int i = 0; i < dataLength; ++i)
206 [hexString appendString:[NSString stringWithFormat:@"%02lx", (unsigned long)dataBuffer[i]]];
207
208 return [NSString stringWithString:hexString];
209}

The documentation for this category was generated from the following files: