Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Iphone AES Encryption using IV,Salt,RFC2898 iteration,Key Generation using SHA1 algo

SoniyaSoniya Posts: 12Registered Users
edited October 2011 in Tutorial Discussion
I am here again with the problem related AES Encryption. The problem is I need to encrypt the string using AES encryption technique with Intialization Vector, Salt, RFC2898 iteration and Generate a key using sha1 algorithm I used this code

+(NSString *)stringToSha1:(NSString *)str{
const char *s = [str cStringUsingEncoding:NSASCIIStringEncoding];
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:@&quot;"];
hash = [hash stringByReplacingOccurrencesOfString:@< withString:@&quot;"];
hash = [hash stringByReplacingOccurrencesOfString:@> withString:@&quot;"];

NSLog(@Hash is %@ for string %@", hash, str);

return hash;
}

for sha1 key generation but it produces totally different as this technique do in .net and android.

Android and .net already have classes and library to do this and i left alone so how I can do it in iphone.

Please any body could help me out for this.

Thanks in advance
Sign In or Register to comment.