• 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
How to encrypt a String to a SHA-1 Encrypted in iPhone
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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

Hi,

In order to get this I found following code, but I need to import some
frameworks into my code. Could somebody kindly point how can achieve SHA-1
Encrypted string in iPhone. I get few errors compiling since I do not have
necessary framework to use this.. :(

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

    // data to Hash
    NSMutableData *dataToHash = [str
dataUsingEncoding:NSUTF8StringEncoding];

    unsigned char hashBytes[CC_SHA1_DIGEST_LENGTH];
    CC_SHA1([dataToHash bytes], [dataToHash length], hashBytes);
    NSData *encodedData = [NSData dataWithBytes:hashBytes
length:CC_SHA1_DIGEST_LENGTH];
    [dataToHash release];
    NSString *encodedStr = [NSString stringWithUTF8String:[encodedData
bytes]];
    //NSString *encodedStr = [[NSString alloc]  initWithBytes:[encodedData
bytes]

//
length:[encodedData length] encoding: NSUTF8StringEncoding];
    NSLog(@"ENCODED SHA-1: %@", encodedStr);

    return encodedStr;

}

Thank you,

Tharindu.
_______________________________________________

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: Tharindu Madushanka <email@hidden>
  • Prev by Date: Video player dead?
  • Next by Date: Re: Video player dead?
  • Previous by thread: Re: Video player dead?
  • Next by thread: Re: How to encrypt a String to a SHA-1 Encrypted in iPhone
  • Index(es):
    • Date
    • Thread