• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to encrypt a String to a SHA-1 Encrypted in iPhone
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to encrypt a String to a SHA-1 Encrypted in iPhone


  • Subject: Re: How to encrypt a String to a SHA-1 Encrypted in iPhone
  • From: Tharindu Madushanka <email@hidden>
  • Date: Sat, 27 Nov 2010 14:09:15 +0530

Hi,

It was just I need to add <CommonCrypto/CommonHMAC.h> header. But above code
didn't work. But following encoded to SHA-1 correctly..

I would like to know whether it encodes right ? or Not ?

<CommonCrypto/CommonHMAC.h>

+(NSString *)stringToSha1:(NSString *)hashkey{

    // Using UTF8Encoding
    const char *s = [hashkey cStringUsingEncoding:NSUTF8StringEncoding];
    NSData *keyData = [NSData dataWithBytes:s length:strlen(s)];

    // This is the destination
    uint8_t digest[CC_SHA1_DIGEST_LENGTH] = {0};
    // This one function does an unkeyed SHA1 hash of your hash data
    CC_SHA1(keyData.bytes, keyData.length, digest);

    // Now convert to NSData structure to make it usable again
    NSData *out = [NSData dataWithBytes:digest
length:CC_SHA1_DIGEST_LENGTH];
    // description converts to hex but puts <> around it and spaces every 4
bytes
    NSString *hash = [out description];
    hash = [hash stringByReplacingOccurrencesOfString:@" " withString:@""];
    hash = [hash stringByReplacingOccurrencesOfString:@"<" withString:@""];
    hash = [hash stringByReplacingOccurrencesOfString:@">" withString:@""];
    // hash is now a string with just the 40char hash value in it

    return hash;

}
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to encrypt a String to a SHA-1 Encrypted in iPhone
      • From: Aaron Burghardt <email@hidden>
References: 
 >How to encrypt a String to a SHA-1 Encrypted in iPhone (From: Tharindu Madushanka <email@hidden>)

  • Prev by Date: Re: Video player dead?
  • Next by Date: iOS - Help with nasty memory leak
  • Previous by thread: How to encrypt a String to a SHA-1 Encrypted in iPhone
  • Next by thread: Re: How to encrypt a String to a SHA-1 Encrypted in iPhone
  • Index(es):
    • Date
    • Thread