ファイルのアップロードジョブを実行しています。私はSHA256とCRC32ハッシュを生成したい。誰も私がそれらのハッシュを生成する方法私を助けることができますか?私はそれをiOSのために働かせたい。iosでSHA256とCRC32を生成する方法
答えて
ためSHA256がCommonCryptoで提供されています....動作するはずです。 CRC32はハッシュではなく、巡回冗長検査です。
例コード:
#import <CommonCrypto/CommonDigest.h>
NSData *dataIn = [@"Now is the time for all good computers to come to the aid of their masters." dataUsingEncoding:NSASCIIStringEncoding];
NSMutableData *macOut = [NSMutableData dataWithLength:CC_SHA256_DIGEST_LENGTH];
CC_SHA256(dataIn.bytes, dataIn.length, macOut.mutableBytes);
NSLog(@"dataIn: %@", dataIn);
NSLog(@"macOut: %@", macOut);
のNSLog出力:
ストリームdataIn:< 4e6f7720 69732074 68652074 696d6520 666f7220 616c6c20 676f6f64 20636f6d 70757465 72732074 6f20636f 6d652074 6f207468 65206169 64206f66 20746865 6972206d 61737465 72732e>
macOut:< 53f89cf6 7ebfbe56 89f1f76a 3843dfd1 09d68c5b a938dcd2 9a12004e 108260cb>
Yagneshにはうってつけの試みですが、元のポスターは自分のプログラムでSHA256とCRC32の数字をプログラムでアップロードする方法を尋ねています。 –
@MichaelDautermannはいそうです。あなたには何か提案がありますか? – NSCry
あなたはこの関連する質問/回答に役立つヒントを得るかもしれません(http://stackoverflow.com/questions/1847281/commoncrypto-is-no-longer-part-of-the-iphone-sdk-where-else -can-i-get-a-a)、@ARC。 –
これらの両方について、
https://gist.github.com/paul-delange/6808278
および実施例
NSString* crc32 = (__bridge NSString*)TGDFileHashCreateWithPath((__bridge CFStringRef)filepath, TGDFileHashDefaultChunkSizeForReadingData, TGDChecksumAlgorithmCRC32);
素敵です。ありがとうございました。 – Drakes
ファイルパスからiOSでのgcloudで使用されるCRC32Cを生成するこの方法Nこの要旨を使います。標準のcrc32でCRC32_POLYNOMIALの他の値のコメントを外したい場合は、
これは512KBのチャンクで指定されたファイルを読み取ります。したがって、大きなファイルで使用できます。
- (NSString*) crc32c:(NSString*)filepath{
/// using crc code from
// http://classroomm.com/objective-c/index.php?action=printpage;topic=2891.0
// by rgronlie
//this is the standard crc32 polynomial
//uint32_t CRC32_POLYNOMIAL = 0xEDB88320;
//this is the crc32c one
uint32_t CRC32_POLYNOMIAL = 0x82F63B78L;
uint32_t CRC32C_SEED = 0xFFFFFFFFL;
// create and populate a lookup table
uint32_t* pCRCTable = malloc(sizeof(uint32_t) * 256);
for (uint32_t i = 0; i <= 255; i++)
{
uint32_t crc32 = i;
for (uint32_t j = 8; j > 0; j--)
{
if ((crc32 & 1) == 1)
crc32 = (crc32 >> 1)^CRC32_POLYNOMIAL;
else
crc32 >>= 1;
}
pCRCTable[i] = crc32;
}
// get a handle to the file
NSFileHandle *filehandle = [NSFileHandle fileHandleForReadingAtPath:filepath];
if(filehandle == NULL){
NSLog(@"failed to create file handle");
return nil;
}
// a buffer to read into
NSData* databuffer;
uint32_t crc = CRC32C_SEED;
// read the file in chunks of 512KB
while(true){
databuffer = [filehandle readDataOfLength: 512 * 1024];
// if there is nothing left finish
if([databuffer length] == 0){
break;
}
// otherwise run each chunk through the lookup table
uint8_t *pBytes = (uint8_t *)[databuffer bytes];
uint32_t length = [databuffer length];
while (length--)
{
crc = (crc>>8)^pCRCTable[(crc & 0xFF)^*pBytes++];
}
}
// clean up
[filehandle closeFile];
free(pCRCTable);
// this is the result
uint32_t hash = crc^0xFFFFFFFFL;
// reverse it for endianness
uint32_t hash_reversed = CFSwapInt32HostToBig(hash);
// as raw bytes
NSData* hash_data = [NSData dataWithBytes: &hash_reversed length: sizeof(hash_reversed)];
// return base64 encoded
return [hash_data base64EncodedStringWithOptions:0];
}
- 1. 生成SHA256は、iOS
- 2. 標準CRC32を生成するようにSTM32を設定する方法
- 3. RSA SHA256署名の生成と検証
- 4. PythonとJava MAC SHA256エンコーディングを生成するには
- 5. HMAC-SHA256 - 方法?
- 6. C#/ Bouncy CastleでPBKDF2-SHA256パスワードハッシュを作成する方法
- 7. Androidでハッシュ文字列を生成するsha256
- 8. C#でSHA256暗号化文字列を生成するには?
- 9. AngularJSでHMAC-SHA256を生成するには?
- 10. iOS - ランドスケープでPDFを生成する方法
- 11. PHPのハッシュ( 'crc32')とcrc32()は別の値を返します
- 12. iOS:ランダムなパステルカラーの生成方法
- 13. ios - UIBackgroundTaskIdentifierがbeginBackgroundTaskで生成する方法
- 14. Angular2では、生成されたファイルのSHA256ハッシュが他のサイトのSHA256と一致しません。
- 15. HMACとSHA256 - nonceを使って検証する方法
- 16. iOSでマイクロアプリを作成する方法
- 17. iOSでカスタムジェスチャーを作成する方法
- 18. SHA256は、PythonとVB.NETで値をハッシングすると、異なるハッシュを生成する
- 19. Reactネイティブプロジェクトのapkまたはiosファイルを生成する方法
- 20. 逆転するCRC32
- 21. 文字列のCRC32を計算する方法
- 22. Aix:AIX/etc/security/passwdで有効なsha1/sha256/sha512パスワードハッシュを生成するには?
- 23. iosとandroidでuidが割り当てられ、生成される方法
- 24. sha256ハッシュをAESでキー暗号化する方法++
- 25. Java Card 2.2.1でSHA256を実装する方法は?
- 26. PHPで大きいファイルのsha256を計算する方法
- 27. iOSとAndroidのコード生成
- 28. JavaScript/NodeでSHA256ハッシュとBase64文字列エンコーディングを計算する方法
- 29. Golang crypto/sha256 - 同じ入力が異なる出力を生成する
- 30. apache cassandraでプライマリキー(自動生成シーケンス)を生成する方法
グーグルで試しましたか? – Dani
@ダニそうでした。 – NSCry