Previously implemented in the blog SHA1 Security has not met the needs of users, today the implementation of the sha224/sha256/sha384/sha512 attached. The SHA that Secure Hash algorithm (safe hashing algorithm) has many kinds of different bit number realization, common has sha224/sha256/sha384/sha512 and so on
SHA224:
|
-(nsstring*) sha224
{
const char *cstr = [self cstringusingencoding:nsutf8stringencoding];
NSData *data = [NSData datawithbytes:cstr length:self.length];
uint8_t Digest[cc_sha224_digest_length];
cc_sha224 (Data.bytes, Data.length, Digest);
nsmutablestring* output = [nsmutablestring stringwithcapacity:cc_sha224_digest_length * 2];
for (int i = 0; i < cc_sha224_digest_length i++)
[Output appendformat:@ "%02x", Digest[i]];
return output;
} |
SHA256:
|
-(nsstring*) sha256
{
const char *cstr = [self cstringusingencoding:nsutf8stringencoding];
NSData *data = [NSData datawithbytes:cstr length:self.length];
uint8_t Digest[cc_sha256_digest_length];
cc_sha256 (Data.bytes, Data.length, Digest);
nsmutablestring* output = [nsmutablestring stringwithcapacity:cc_sha256_digest_length * 2];
for (int i = 0; i < cc_sha256_digest_length i++)
[Output appendformat:@ "%02x", Digest[i]];
return output;
} |
SHA384:
|
-(nsstring*) sha384
{
const char *cstr = [self cstringusingencoding:nsutf8stringencoding];
NSData *data = [NSData datawithbytes:cstr length:self.length];
uint8_t Digest[cc_sha384_digest_length];
cc_sha384 (Data.bytes, Data.length, Digest);
nsmutablestring* output = [nsmutablestring stringwithcapacity:cc_sha384_digest_length * 2];
for (int i = 0; i < cc_sha384_digest_length i++)
[Output appendformat:@ "%02x", Digest[i]];
return output;
} |
SHA512:
|
-(nsstring*) sha512
{
const char *cstr = [self cstringusingencoding:nsutf8stringencoding];
NSData *data = [NSData datawithbytes:cstr length:self.length];
uint8_t Digest[cc_sha512_digest_length];
cc_sha512 (Data.bytes, Data.length, Digest);
nsmutablestring* output = [nsmutablestring stringwithcapacity:cc_sha512_digest_length * 2];
for (int i = 0; i < cc_sha512_digest_length i++)
[Output appendformat:@ "%02x", Digest[i]];
return output;
} |
Put together a great unity
|
NSSTRING+SHA.H//#import <Foundation/Foundation.h> #import <CommonCrypto/CommonDigest.h> #import
<CommonCrypto/CommonCryptor.h> @interface NSString (SHA)-(NSString *) SHA1;
-(NSString *) sha224;
-(NSString *) sha256;
-(NSString *) sha384;
-(NSString *) sha512; @end////NSSTRING+SHA.M//#import "Nsstring+sha.h" @implementation nsstring (SHA)-(nsstring*) SHA1 {const-ch
Ar *cstr = [self cstringusingencoding:nsutf8stringencoding];
NSData *data = [NSData datawithbytes:cstr length:self.length];
uint8_t Digest[cc_sha1_digest_length];
CC_SHA1 (Data.bytes, 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*) sha224 {const char *cstr = [self cstringusingencoding:nsutf8stringencoding]; NSData *data = [NSData datawithbytes:cstr length:self.length]; uint8_t Digest[cc_sha |