CBHDigestKit 1.3

CBHDigestKit 1.3

Maintained by Chris Huxtable.



CBHDigestKit

release pod licence coverage

Makes calculating digests easy.

Supports:

  • SHA-224
  • SHA-256
  • SHA-386
  • SHA-512
  • SHA-1
  • MD2
  • MD4
  • MD5

Use

CBHDigestKit extends NSData and NSString with a category adding methods for several digests and converting from bytesToHex.

Example:

Compute the SHA-256 digest of a NSString:

NSData *digest = [@"This is a string." sha256UsingEncoding:NSUTF8StringEncoding];

Compute the SHA-256 digest of a NSData:

NSData *digest = [[NSData dataWithContentsOfFile:@"/etc/hosts"] sha256];

Efficently compute the SHA-256 digest of a file:

NSData *digest = [CBHDigester digestStream:[NSInputStream inputStreamWithFileAtPath:@"/etc/hosts"];

Compute and print a digest using an arbitrary algorithm:

CBHDigestAlgorithm algorithm = ...
NSData *data = [NSData dataWithContentsOfFile:@"/etc/hosts"];
NSData *digest = [data digestUsingAlgorithm:algorithm];
NSLog(@"0x%@", [digest bytesToHex]);

Licence

CBHDigestKit is available under the ISC license.