美文网首页
使用Base64编解码NSData和NSString对象

使用Base64编解码NSData和NSString对象

作者: Cooperluffy丨路飞 | 来源:发表于2017-06-22 15:45 被阅读1223次

    本文转自:https://itony.me/488.html

       
        NSData *nsdata = [@"iOS Developer Tips encode in Base64" dataUsingEncoding:NSUTF8StringEncoding];
        
        //根据NSData生成Base64编码的String
        NSString *base64Encode = [nsdata base64EncodedStringWithOptions:0];
        NSLog(@"Encode:%@", base64Encode);
        
        //NSData生成未编码的NSString
        NSString *noCodeString = [[NSString alloc]initWithData:nsdata encoding:NSUTF8StringEncoding];
        NSLog(@"noCodeString:%@",noCodeString);
        
        //NSData from  the base64 encoded str
        NSData *nsdataFromBase64String = [[NSData alloc]initWithBase64EncodedString:base64Encode options:0];
        
        
        //Decode NSString from NSData
        NSString *base64Decode = [[NSString alloc]initWithData:nsdata encoding:NSUTF8StringEncoding];
        NSLog(@"base64Decode:%@",base64Decode);
    

    相关文章

      网友评论

          本文标题:使用Base64编解码NSData和NSString对象

          本文链接:https://www.haomeiwen.com/subject/jwefcxtx.html