- Fix PNInstallation
This commit is contained in:
1 parent
8ad99ddd70
commit
2e2ed83e95
47 files changed
+5914
-3778
No files matched your search
@@ -10,6 +10,8 @@
|
||||
|
||||
@interface NSString (Helper)
|
||||
|
||||
+ (NSString *) getRandString: (int) length;
|
||||
|
||||
- (BOOL) isValidEmail;
|
||||
|
||||
- (BOOL) isNumeric;
|
||||
@@ -20,4 +22,12 @@
|
||||
|
||||
- (BOOL) isValidTaxCode;
|
||||
|
||||
- (NSString *) md5;
|
||||
|
||||
- (NSString*) sha1;
|
||||
|
||||
- (NSString*) sha256;
|
||||
|
||||
- (NSString*) sha512;
|
||||
|
||||
@end
|
||||
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import "NSString+Helper.h"
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
@implementation NSString (Helper)
|
||||
|
||||
@@ -58,4 +59,84 @@
|
||||
return [urlTest evaluateWithObject:self];
|
||||
}
|
||||
|
||||
#pragma mark - Random String Method
|
||||
|
||||
+ (NSString *) getRandString: (int) length {
|
||||
|
||||
NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
|
||||
NSMutableString *randomString = [NSMutableString stringWithCapacity: length];
|
||||
|
||||
for (int i=0; i<length; i++) {
|
||||
[randomString appendFormat: @"%C", [letters characterAtIndex: arc4random() % [letters length]]];
|
||||
}
|
||||
|
||||
return randomString;
|
||||
}
|
||||
|
||||
- (NSString *) md5 {
|
||||
const char *cStr = [self UTF8String];
|
||||
unsigned char digest[16];
|
||||
CC_MD5( cStr, (CC_LONG)strlen(cStr), digest ); // This is the md5 call
|
||||
|
||||
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
|
||||
|
||||
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
|
||||
[output appendFormat:@"%02x", digest[i]];
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
- (NSString*) sha1 {
|
||||
|
||||
const char *cstr = [self cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:cstr length:self.length];
|
||||
|
||||
uint8_t digest[CC_SHA1_DIGEST_LENGTH];
|
||||
|
||||
CC_SHA1(data.bytes, (CC_LONG)data.length, digest);
|
||||
|
||||
NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
|
||||
|
||||
for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
|
||||
[output appendFormat:@"%02x", digest[i]];
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
- (NSString*) sha256 {
|
||||
|
||||
const char *s=[self cStringUsingEncoding:NSASCIIStringEncoding];
|
||||
NSData *keyData=[NSData dataWithBytes:s length:strlen(s)];
|
||||
|
||||
uint8_t digest[CC_SHA256_DIGEST_LENGTH]={0};
|
||||
CC_SHA256(keyData.bytes, (CC_LONG)keyData.length, digest);
|
||||
NSData *out=[NSData dataWithBytes:digest length:CC_SHA256_DIGEST_LENGTH];
|
||||
NSString *hash=[out description];
|
||||
hash = [hash stringByReplacingOccurrencesOfString:@" " withString:@""];
|
||||
hash = [hash stringByReplacingOccurrencesOfString:@"<" withString:@""];
|
||||
hash = [hash stringByReplacingOccurrencesOfString:@">" withString:@""];
|
||||
return hash;
|
||||
}
|
||||
|
||||
- (NSString*) sha512 {
|
||||
|
||||
const char *s=[self cStringUsingEncoding:NSASCIIStringEncoding];
|
||||
NSData *keyData=[NSData dataWithBytes:s length:strlen(s)];
|
||||
|
||||
uint8_t digest[CC_SHA512_DIGEST_LENGTH]={0};
|
||||
CC_SHA512(keyData.bytes, (CC_LONG)keyData.length, digest);
|
||||
NSData *out=[NSData dataWithBytes:digest length:CC_SHA512_DIGEST_LENGTH];
|
||||
NSString *hash=[out description];
|
||||
hash = [hash stringByReplacingOccurrencesOfString:@" " withString:@""];
|
||||
hash = [hash stringByReplacingOccurrencesOfString:@"<" withString:@""];
|
||||
hash = [hash stringByReplacingOccurrencesOfString:@">" withString:@""];
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user