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0ZTkyMjM2ODI3MjFhYTI3OWI+PGlkXzgwMTVlNmQ0ZGRmYjky NDE4ODcxMWIzMGE5MWQzZGU4IE11bHRpcGxlQ2hvaWNlPSJ0cnVlIj4gPC9pZF84MDE1ZTZkNGRk ZmI5MjQxODg3MTFiMzBhOTFkM2RlOD48L2lkXzM2ZjI3ZjBjZTE0NjYwNGU5MjIzNjgyNzIxYWEy NzliPjxpZF9mN2FjMTgzODA5YjYwMTQxODFlZTRhMDQyMjRmMTUzZT48aWRfMjBhMzg0OWIwMDEwYjk0YWFhNGJhNDEwYTRkNzY2ZWI+PC9pZF8yMGEzODQ5YjAwMTBiOTRhYWE0YmE0MTBhNGQ3NjZl Yj48L2lkX2Y3YWMxODM4MDliNjAxNDE4MWVlNGEwNDIyNGYxNTNlPjwvcmVzdWx0PjxyZXBsYWNl YWJsZXMvPjxzeXN0ZW1wYXJhbWxvY2F0aW9uPmh0dHA6Ly9TdXJ2ZXlSZXAvQ1JNX1NWWV9CU1Bf U1lTVEVNUEFSQU1fSEFSSVRfVEVTVC5YTUw8L3N5c3RlbXBhcmFtbG9jYXRpb24+PGhpZGRlbi8+ PHJlYWRPbmx5Lz48bWFuZGF0b3J5Lz48bm9EaXNwbGF5Lz48YWRkSXRlbXMvPjxzY3JpcHQvPjxv bkV2ZW50Lz48L3N1cnZleT4=

4

1 回答 1

2

谷歌上的第二个结果是这样的:

- (NSString *)base64Encode:(NSString *)plainText
{
  NSData *plainTextData = [plainText dataUsingEncoding:NSUTF8StringEncoding];
  NSString *base64String = [plainTextData base64EncodedString];
  return base64String;
}
 
- (NSString *)base64Decode:(NSString *)base64String
{
  NSData *plainTextData = [NSData dataFromBase64String:base64String];
  NSString *plainText = [[NSString alloc] initWithData:plainTextData encoding:NSUTF8StringEncoding];
  return plainText;
}

http://aerson.net/base64-encode-and-decode-nsstring-cocoa

于 2012-09-07T06:37:37.703 回答