iphone 加密汇总

MD5
- (NSString *)createMD5:(NSString *)signString
{
    constchar*cStr =[signStringUTF8String];
    unsignedchar result[16];
    CC_MD5(cStr,strlen(cStr), result);
    return[NSStringstringWithFormat:
          @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
           result[0], result[1], result[2], result[3],
           result[4], result[5], result[6], result[7],
           result[8], result[9], result[10], result[11],
           result[12], result[13], result[14], result[15]
           ];
}

RC4  aInput要加密,aKey密钥

- (NSString*)createRC4:(NSString*)aInput key:(NSString*)aKey

{

    

    NSMutableArray *iS = [[NSMutableArrayalloc]initWithCapacity:256];

    NSMutableArray *iK = [[NSMutableArrayalloc]initWithCapacity:256];

    

    for (int i= 0; i<256; i++) {

        [iS addObject:[NSNumbernumberWithInt:i]];

    }

    int j=1;

    for (short i=0; i<256; i++) {    

        UniChar c = [aKey characterAtIndex:i%aKey.length];

        

        [iK addObject:[NSNumbernumberWithChar:c]];

    }

    

    j=0;

    

    for (int i=0; i<255; i++) {

        int is = [[iS objectAtIndex:i]intValue];

        UniChar ik = (UniChar)[[iKobjectAtIndex:i]charValue];

        j = (j + is + ik)%256;

        NSNumber *temp = [iS objectAtIndex:i];

        [iS replaceObjectAtIndex:iwithObject:[iSobjectAtIndex:j]];

        [iS replaceObjectAtIndex:jwithObject:temp];

        

    }

    

    int i=0;

    j=0;  

    NSString *result = aInput;  

    for (short x=0; x<[aInputlength]; x++) {

        i = (i+1)%256;    

        int is = [[iS objectAtIndex:i]intValue];

        j = (j+is)%256;      

        int is_i = [[iS objectAtIndex:i]intValue];

        int is_j = [[iS objectAtIndex:j]intValue]; 

        

        int t = (is_i+is_j) % 256;

        int iY = [[iS objectAtIndex:t]intValue];

        

        UniChar ch = (UniChar)[aInputcharacterAtIndex:x];

        UniChar ch_y = ch^iY;

        

        result = [result stringByReplacingCharactersInRange:NSMakeRange(x,1)withString:[NSStringstringWithCharacters:&ch_ylength:1]];

    }

    

    [iS release];

    [iK release];

    

    return result;

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值