0
C#コード。SHA1を使用したC#とIOSの暗号化
SHA1 hash = SHA1.Create();
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] combined = encoder.GetBytes(password);
hash.ComputeHash(combined);
passwordHash = Convert.ToBase64String(hash.Hash);
IOSでどのように同じ結果を得ることができますか?私を助けてください。
これまでのところ、私はこれだけをやったが、結果はC#
NSString *password = @"XABCVKXMWJ"; // your password
CFIndex asciiLength;
// Determine length of converted data:
CFStringGetBytes((__bridge CFStringRef)(password), CFRangeMake(0, [password length]),
kCFStringEncodingASCII, '?', false, NULL, 0, &asciiLength);
// Allocate buffer:
uint8_t *asciiBuffer = malloc(asciiLength);
// Do the conversion:
CFStringGetBytes((__bridge CFStringRef)(password), CFRangeMake(0, [password length]),
kCFStringEncodingASCII, '?', false, asciiBuffer, asciiLength, NULL);
unsigned char hash[CC_SHA1_DIGEST_LENGTH];
CC_SHA1(asciiBuffer, asciiLength, hash);
free(asciiBuffer);
NSData *result = [NSData dataWithBytes:hash length:CC_SHA1_DIGEST_LENGTH];
とは異なっている私はC#のコードから取得していた結果は、それがある、 uSFCLAZZHkBVN7xViO3hKkhhR/S =
およびIOSからです uSFCLAZZHkBVN7xViO3hKkhhR + s =
ただ、サイドノート:ハッシュが_not_暗号化です! –
iOSでCommonCryptoライブラリを使用できます。 – Paulw11