Im trying to make same Sha1 out put in IOS but the result aren't the same.
Due to this answer SO it should be fine and same result
this is my C# Code :
using (SHA1 sha1Hash = SHA1.Create())
{
string hash1 = GetSHA1Hash(sha1Hash, "8390495498");
}
static string GetSHA1Hash(SHA1 sha1Hash, string input)
{
byte[] data = sha1_Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
return sBuilder.ToString();
}
the result is : d763bd0b5b346a3c95eb4f2912be40c2ce6f0a41
And my Objective C code :
[sh1obj sha1:@"8390495498"]
- (NSString *)sha1:(NSString *)str {
NSData *data = [str dataUsingEncoding:NSUnicodeStringEncoding];
NSString *unicodePassword = [[NSString alloc] initWithData:data encoding:NSUnicodeStringEncoding];
data = [unicodePassword dataUsingEncoding:NSUnicodeStringEncoding];
data = [NSData dataWithBytes:[data bytes] + 2 length:[data length] - 2];
unsigned char hash[CC_SHA1_DIGEST_LENGTH];
CC_SHA1([data bytes], [data length], hash);
NSData *result = [NSData dataWithBytes:hash length:CC_SHA1_DIGEST_LENGTH];
NSLog(@"Result: %@",result);
return result;
}
the result is : <241cdda1 6867aaad cb69faed d0975579 f6ec3a07>
i even tried this one too :
[sh1obj sha1:@"8390495498"]
- (NSString *)sha1:(NSString *)str {
const char *cStr = [str UTF8String];
unsigned char result[CC_SHA1_DIGEST_LENGTH];
CC_SHA1(cStr, strlen(cStr), result);
NSString *s = [NSString stringWithFormat:
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
result[0], result[1], result[2], result[3], result[4],
result[5], result[6], result[7],
result[8], result[9], result[10], result[11], result[12],
result[13], result[14], result[15],
result[16], result[17], result[18], result[19]
];
NSLog(@"Result: %@",s);
return s;
}
and the result was : cbdb5d7936ac9a56846cabad5e9d41942a08b49c