• Stars
    star
    1,131
  • Rank 39,753 (Top 0.9 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created about 12 years ago
  • Updated over 4 years ago

Reviews

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

Repository Details

Encrypt/Decrypt: AES. Hash: MD5, SHA(SHA1, SHA224, SHA256, SHA384, SHA512). Encode/Decode: Base64, Hex.

#CocoaSecurity Build Status

Kelp https://twitter.com/kelp404/
[MIT License][mit]
[MIT]: http://www.opensource.org/licenses/mit-license.php

CocoaSecurity include 4 classes, CocoaSecurity, CocoaSecurityResult, CocoaSecurityEncoder and CocoaSecurityDecoder.

##CocoaSecurity CocoaSecurity is core. It provides AES encrypt, AES decrypt, Hash(MD5, HmacMD5, SHA1SHA512, HmacSHA1HmacSHA512) messages.

MD5:

CocoaSecurityResult *md5 = [CocoaSecurity md5:@"kelp"];

// md5.hex = 'C40C69779E15780ADAE46C45EB451E23'
// md5.hexLower = 'c40c69779e15780adae46c45eb451e23'
// md5.base64 = 'xAxpd54VeAra5GxF60UeIw=='

SHA256:

CocoaSecurityResult *sha256 = [CocoaSecurity sha256:@"kelp"];

// sha256.hexLower = '280f8bb8c43d532f389ef0e2a5321220b0782b065205dcdfcb8d8f02ed5115b9'
// sha256.base64 = 'KA+LuMQ9Uy84nvDipTISILB4KwZSBdzfy42PAu1RFbk='

default AES Encrypt:
key -> SHA384(key).sub(0, 32)
iv -> SHA384(key).sub(32, 16)

CocoaSecurityResult *aesDefault = [CocoaSecurity aesEncrypt:@"kelp" key:@"key"];

// aesDefault.base64 = 'ez9uubPneV1d2+rpjnabJw=='

AES256 Encrypt & Decrypt:

CocoaSecurityResult *aes256 = [CocoaSecurity aesEncrypt:@"kelp"
                                      hexKey:@"280f8bb8c43d532f389ef0e2a5321220b0782b065205dcdfcb8d8f02ed5115b9"
                                       hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
// aes256.base64 = 'WQYg5qvcGyCBY3IF0hPsoQ=='

CocoaSecurityResult *aes256Decrypt = [CocoaSecurity aesDecryptWithBase64:@"WQYg5qvcGyCBY3IF0hPsoQ==" 
                                      hexKey:@"280f8bb8c43d532f389ef0e2a5321220b0782b065205dcdfcb8d8f02ed5115b9"
                                       hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
// aes256Decrypt.utf8String = 'kelp'

##CocoaSecurityResult CocoaSecurityResult is the result class of CocoaSecurity. It provides convert result data to NSData, NSString, HEX string, Base64 string.

@property (strong, nonatomic, readonly) NSData *data;
@property (strong, nonatomic, readonly) NSString *utf8String;
@property (strong, nonatomic, readonly) NSString *hex;
@property (strong, nonatomic, readonly) NSString *hexLower;
@property (strong, nonatomic, readonly) NSString *base64;

##CocoaSecurityEncoder CocoaSecurityEncoder provides convert NSData to HEX string, Base64 string.

- (NSString *)base64:(NSData *)data;
- (NSString *)hex:(NSData *)data useLower:(BOOL)isOutputLower;

example:

CocoaSecurityEncoder *encoder = [CocoaSecurityEncoder new];
NSString *str1 = [encoder hex:[@"kelp" dataUsingEncoding:NSUTF8StringEncoding] useLower:NO];
// str1 = '6B656C70'
NSString *str2 = [encoder base64:[@"kelp" dataUsingEncoding:NSUTF8StringEncoding]];
// str2 = 'a2VscA=='

##CocoaSecurityDecoder CocoaSecurityEncoder provides convert HEX string or Base64 string to NSData.

- (NSData *)base64:(NSString *)data;
- (NSData *)hex:(NSString *)data;

example:

CocoaSecurityDecoder *decoder = [CocoaSecurityDecoder new];
NSData *data1 = [decoder hex:@"CC0A69779E15780ADAE46C45EB451A23"];
// data1 = <cc0a6977 9e15780a dae46c45 eb451a23>
NSData *data2 = [decoder base64:@"zT1PS64MnXIUDCUiy13RRg=="];
// data2 = <cd3d4f4b ae0c9d72 140c2522 cb5dd146>

##Installation

  1. git:
$ git clone git://github.com/kelp404/CocoaSecurity.git
$ cd CocoaSecurity
$ git submodule update --init
  1. CocoadPods:
    add Podfile in your project path
platform :ios
pod 'CocoaSecurity'
$ pod install

More Repositories

1

angular-form-builder

Drag and drop to build bootstrap forms in AngularJS.
CoffeeScript
602
star
2

angular-validator

AngularJS form validation.
CoffeeScript
162
star
3

NyaruDB

A simple NoSQL database(key-value pair) in Objective-C. It runs on iOS and OS X.
Objective-C
140
star
4

Victory

An error reporting server in Python. It runs on Google App Engine.
Python
30
star
5

electron-s3-file-manager

A GUI AWS S3 file manager. It supports keyword search, download, upload and preview video.
JavaScript
19
star
6

Flask-GAE

This is my Flask Google App Engine template.
Python
19
star
7

Victorique

An error report server on Google App Engine.
Python
16
star
8

bull-admin-panel

A real time admin panel of Bull(Redis-based queue) based on Express and WebSocket.
JavaScript
14
star
9

enju

An Elasticsearch client on Node.js written in CoffeeScript.
CoffeeScript
13
star
10

AlertView

AlertView is a jQuery plugin that provides alerting message. That are like OS X notification window, and Twitter alert message.
CoffeeScript
12
star
11

mongoose-profiler

A performance tuning tool for Mongoose. Show explain results when the query is slow.
JavaScript
11
star
12

anya-s3-file-manager

An AWS S3 file manager. It supports keyword search, upload, preview video and archive files into a zip then download it.
JavaScript
7
star
13

CoffeeCocoa

Run CoffeeScript and JavaScript in Objective-C.
Objective-C
6
star
14

tina

An elasticsearch client on Python 3.4 for django.
Python
6
star
15

ValueInjector

Cocoa ValueInjector provides converting weak typing to strong typing. Injecting value from NSDictionary to custom class and initialization NSDictionary with custom class.
Objective-C
5
star
16

NyaruDB-Control

A management tool for NyaruDB which is a simple NoSQL database in Objective-C.
CoffeeScript
5
star
17

react-hooks-shared-state

A global state for React with Hooks API.
JavaScript
4
star
18

quick-jump

Quickly navigate the cursor to any position visible in the editor like AceJump.
CoffeeScript
4
star
19

Maguro

A contact us library for UserVoice.
Objective-C
4
star
20

Tower-of-Saviors

The Tower of Saviors gallery.
CoffeeScript
3
star
21

angularjs-bootstrap-datepicker

A Bootstrap3 datepicker for AngularJS.
CoffeeScript
3
star
22

capybara-router

Unfancy react router without flux and redux.
JavaScript
3
star
23

kue-admin-panel

An admin panel of Kue based on WebSocket.
JavaScript
2
star
24

current-device

This repository is for bower. $ bower install current-device -S
JavaScript
2
star
25

test

Dockerfile
2
star
26

phantom-worker

A PhantomJS worker. Execute the Single Page Application then return html.
JavaScript
2
star
27

poi-router

An AngularJS router.
CoffeeScript
2
star
28

dailydrinks

A drinks order web.
JavaScript
2
star
29

Django-GAE

The Django site on Google App Engine.
Python
2
star
30

d3-geo-projection

1
star
31

Victory-iOS

Victory iOS demo code. An error and crash reporter example code.
Objective-C
1
star
32

Salmon

Salmon issue tracker.
Python
1
star
33

photo-base

HTML
1
star
34

real-estate-lab

不動產投報率試算工具。
JavaScript
1
star
35

changelog.config

A conventional-changelog config.
JavaScript
1
star
36

react-datepicker

A react datepicker.
JavaScript
1
star