Base加密与解密

//base64加密 时不能与要加密的字符串冲突,有+ / % 等的

  • (void)encodeBase64
    {
    NSString *sourceStr = @"base64加密";
    NSData *sourceData = [sourceStr dataUsingEncoding:NSUTF8StringEncoding];
    NSString *result = [sourceData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    //调用解密
    [self dCoderBase64WithString:result];
    NSLog(@"加密---%@",result);
    }

//base64解密 参数为base64加密之后的字符串
-(void)dCoderBase64WithString:(NSString *)base64_string
{
//解码成二进制流
NSData *data = [[NSData alloc]initWithBase64EncodedString:base64_string options:NSDataBase64DecodingIgnoreUnknownCharacters];
NSString *string = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"解密---%@",string);
}

你可能感兴趣的:(Base加密与解密)