• Stars
    star
    351
  • Rank 120,906 (Top 3 %)
  • Language
    Objective-C
  • License
    Apache License 2.0
  • Created almost 12 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

NSHash adds hashing methods to NSString and NSData

Objective-C NSHash

NSHash adds hashing methods to NSString and NSData.

Build Status Cocoapods Compatible Supported Platforms

How to use it

Copy the NSHash classes into your project or add this line to your Podfile:

pod 'NSHash', '~> 1.2.0'

Quick API overview

Import the the category class you need:

#import <NSHash/NSString+NSHash.h>
#import <NSHash/NSData+NSHash.h>

After that you can call MD5, MD5Data, SHA1, SHA1Data, SHA256 or SHA256Data on any NSString:

NSString* string = @"NSHash";

NSLog(@"MD5 as NSString:    %@", [string MD5]);
NSLog(@"SHA1 as NSString:   %@", [string SHA1]);
NSLog(@"SHA256 as NSString: %@", [string SHA256]);
NSLog(@"SHA512 as NSString: %@", [string SHA512]);

NSLog(@"MD5 as NSData:      %@", [string MD5Data]);
NSLog(@"SHA1 as NSData:     %@", [string SHA1Data]);
NSLog(@"SHA256 as NSData:   %@", [string SHA256Data]);
NSLog(@"SHA512 as NSData:   %@", [string SHA512Data]);

This will return a new NSString with a hex code transformed version of the hash:

MD5 as NSString:    ccbe85c2011c5fe3da7d760849c4f99e
SHA1 as NSString:   f5b17712c5d31ab49654b0baadf699561958d750
SHA256 as NSString: 84423607efac17079369134460239541285d5ff40594f9b8b16f567500162d2e
SHA512 as NSString: 927323f74dec1305f0a4822aab380268b6eab030eac4af6c881a529e610936613b0563bca84af894cff1e876522b8f721b54da9bbe3132f8de2692019e195cf8
MD5 as NSData:      <ccbe85c2 011c5fe3 da7d7608 49c4f99e>
SHA1 as NSData:     <f5b17712 c5d31ab4 9654b0ba adf69956 1958d750>
SHA256 as NSData:   <84423607 efac1707 93691344 60239541 285d5ff4 0594f9b8 b16f5675 00162d2e>
SHA512 as NSData:   <927323f7 4dec1305 f0a4822a ab380268 b6eab030 eac4af6c 881a529e 61093661 3b0563bc a84af894 cff1e876 522b8f72 1b54da9b be3132f8 de269201 9e195cf8>

Or call MD5, MD5String, SHA1, SHA1String, SHA256 or SHA256String on any NSData:

NSData* data = [@"NSHash" dataUsingEncoding:NSUTF8StringEncoding];

NSLog(@"MD5 as NSData:      %@", [data MD5]);
NSLog(@"SHA1 as NSData:     %@", [data SHA1]);
NSLog(@"SHA256 as NSData:   %@", [data SHA256]);
NSLog(@"SHA512 as NSData:   %@", [data SHA512]);

NSLog(@"MD5 as NSString:    %@", [data MD5String]);
NSLog(@"SHA1 as NSString:   %@", [data SHA1String]);
NSLog(@"SHA256 as NSString: %@", [data SHA256String]);
NSLog(@"SHA512 as NSString: %@", [data SHA512String]);

Which will return the NSData with the hash as bytes without the hex transformation:

MD5 as NSData:      <ccbe85c2 011c5fe3 da7d7608 49c4f99e>
SHA1 as NSData:     <f5b17712 c5d31ab4 9654b0ba adf69956 1958d750>
SHA256 as NSData:   <84423607 efac1707 93691344 60239541 285d5ff4 0594f9b8 b16f5675 00162d2e>
SHA512 as NSData:   <927323f7 4dec1305 f0a4822a ab380268 b6eab030 eac4af6c 881a529e 61093661 3b0563bc a84af894 cff1e876 522b8f72 1b54da9b be3132f8 de269201 9e195cf8>
MD5 as NSString:    ccbe85c2011c5fe3da7d760849c4f99e
SHA1 as NSString:   f5b17712c5d31ab49654b0baadf699561958d750
SHA256 as NSString: 84423607efac17079369134460239541285d5ff40594f9b8b16f567500162d2e
SHA512 as NSString: 927323f74dec1305f0a4822aab380268b6eab030eac4af6c881a529e610936613b0563bca84af894cff1e876522b8f721b54da9bbe3132f8de2692019e195cf8

The generated doc (still only two categories with only this few methods) is also available on cocoadocs.

More Repositories

1

react-showdown

Render React components within markdown and markdown as React components!
TypeScript
119
star
2

react-native-layout

Semantic layout components for React Native
JavaScript
57
star
3

EventEmitter

Node.js inspired EventEmitter for Objective C
Objective-C
51
star
4

react-native-showdown

React-native component which renders markdown into a webview!
TypeScript
49
star
5

react-native-sidebar

JavaScript
27
star
6

AFCalendarRequestOperation

AFNetworking extension for downloading and parsing calendars.
Objective-C
24
star
7

react-native-cosmos

DX tool to test react-native components with defined props/state fixtures.
JavaScript
20
star
8

react-native-autopilot

Automatically push and pop navigator routes/scenes/screens if the navigator props was changed.
JavaScript
15
star
9

app_icon_template

Sketch template to create Android and iOS app icons
11
star
10

awesome-links

A collection of awesome-* projects as submodules to grep them...
HTML
10
star
11

pixelfed-app

🌈 Pixelfed app for Android and iOS
TypeScript
10
star
12

react-native-examples

A bunch of small and (hopefully) readable react-native examples
JavaScript
8
star
13

reset_simulators

Reset your Xcode simulators to a opinionated mix of iOS devices and versions
Shell
6
star
14

atom-show-in-system

atom.io extension which show and open files within your system
CoffeeScript
6
star
15

react-native-init-history

react-native init history to compare different version
Java
5
star
16

flutter_alert

A Flutter package to simplify alert messages on Android (Material) and iOS (Cupertino).
Dart
4
star
17

linux

Save some finding and configurations
Shell
3
star
18

react-native-with-eslint

react-native example project with ESLint configuration
Objective-C
2
star
19

usepromises

React and React Native hook to consume a Promise (similar to useEffect) with full TypeScript support
TypeScript
2
star
20

talks

JavaScript
2
star
21

comprise

Add layout and partial support to consolidate.js!
JavaScript
2
star
22

tcpproxy

TCPproxy: Throttle your TCP connections now!
JavaScript
2
star
23

java-hardener

Makes java fault tolerant against NPEs!
Java
1
star
24

bo-swag

A lightweight solution to create swagger documentation with ExpressJS
JavaScript
1
star
25

container

TypeScript
1
star
26

kajitsu

Java 8 middleware web application framework.
Java
1
star
27

octopus

🐙 Octopus app
TypeScript
1
star
28

operators

1
star
29

wait-until

a tiny wait-until tool
Go
1
star
30

react-native-openurl

C#
1
star
31

react-native-tutorial

Objective-C
1
star
32

majorityreports

✨ majority reports 🔮
TypeScript
1
star