How to base64 encode string with ios8 and ios9 api without line length limit.
I'm preparing some custom basic authentication and I need to encode credentials according to standard which means:
The resulting string is then encoded using the RFC2045-MIME variant of Base64, except not limited to 76 char/line
In old ios7 there was a method: NSData base64Encoding but now is deprecated and instead of it I have:
- (NSString *)base64EncodedStringWithOptions:
(NSDataBase64EncodingOptions)options NS_AVAILABLE(10_9, 7_0);
and the options are:
typedef NS_OPTIONS(NSUInteger, NSDataBase64EncodingOptions) {
// Use zero or one of the following to control the maximum line length after which a line ending is inserted. No line endings are inserted by default.
NSDataBase64Encoding64CharacterLineLength = 1UL << 0,
NSDataBase64Encoding76CharacterLineLength = 1UL << 1,
// Use zero or more of the following to specify which kind of line ending is inserted. The default line ending is CR LF.
NSDataBase64EncodingEndLineWithCarriageReturn = 1UL << 4,
NSDataBase64EncodingEndLineWithLineFeed = 1UL << 5,
} NS_ENUM_AVAILABLE(10_9, 7_0);
So I can choose line length 64 or 76. The base64 encoding for basic authentication don't have line length limit so how can I approach to this.
如果您不选择任何选项, 则不会添加行尾 。
[myData base64EncodedStringWithOptions:0]; // One long string
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.