如何从aes128解密中删除字符串中的垃圾字符

时间:2012-06-12 08:04:16

标签: iphone objective-c aes encryption

问题是服务器端的加密他们正在使用ISO10126d2Padding并且解密正在发生但是在解密之后它显示了一些垃圾值,任何人请帮助删除:

实际结果= india ismy
* DECRYPTED VALUE =印度ismyg~²t

1 个答案:

答案 0 :(得分:0)

我不会说这是从NSString中删除不需要的字符的最好方法,但我这样做了......而且很棒。

NSString * str = @"your string";
NSMutableString * newString;
int j = [str length];
for (int i=0; i<j; i++) {       
    if (([str characterAtIndex:i] >=65 && [str characterAtIndex:i] <=90) || ([str characterAtIndex:i] >=97 && [str characterAtIndex:i] <=122) ||[str characterAtIndex:i] == 32 ) {
        [newString appendFormat:@"%c",[str characterAtIndex:i]];
    }               
}

//([str characterAtIndex:i] >=65 && [str characterAtIndex:i] <=90) this is ASCII limit for A-Z
//([str characterAtIndex:i] >=97 && [str characterAtIndex:i] <=122) this is ASCII limit for a-z
//and [str characterAtIndex:i] == 32 is for space.

现在,打印新字符串

NSLog(@"%@",newString);

让我知道它是否在为你而战!

谢谢!