Skip to content

touchbyte/CBHDigestKit

Repository files navigation

CBHDigestKit

release pod licence coverage

An easy-to-use category for NSData and NSString to calculate digests.

Supports:

  • SHA224
  • SHA256
  • SHA386
  • SHA512
  • SHA1
  • MD2
  • MD4
  • MD5

Use

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

Example:

Compute the SHA256 digest of a NSString:

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

Compute the SHA256 digest of a NSData:

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

Compute and print SHA256 digest of a file:

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

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.

About

Makes calculating digests easy.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 96.2%
  • C 3.8%