no message

This commit is contained in:
Giuseppe Nucifora 2016-12-29 15:47:15 +01:00
parent 5bdac671f9
commit 0b0803f3f9
1292 changed files with 21890 additions and 30219 deletions

View File

@ -7,7 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
2EC5979E315D48625574D725 /* Pods_PNObject_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 808511432137F18DDFE44210 /* Pods_PNObject_Tests.framework */; };
6003F58E195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; };
6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58F195388D20070C39A /* CoreGraphics.framework */; };
6003F592195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; };
@ -22,7 +21,8 @@
6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; };
6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; };
873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; };
FD9FF8837F786E50B88531C0 /* Pods_PNObject_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F74BC1D549B9C619883DB7E0 /* Pods_PNObject_Example.framework */; };
BCF991672BE36A8FE7F43A6B /* libPods-PNObject_Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E7FCF35EF87A5BDD07CA6CD2 /* libPods-PNObject_Tests.a */; };
C52729592D50CEDEC002ADC9 /* libPods-PNObject_Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0ABF8340F735722CEE937FA3 /* libPods-PNObject_Example.a */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -36,6 +36,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
0ABF8340F735722CEE937FA3 /* libPods-PNObject_Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-PNObject_Example.a"; sourceTree = BUILT_PRODUCTS_DIR; };
116AF818F8117B91EF290C9A /* Pods-PNObject_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PNObject_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-PNObject_Example/Pods-PNObject_Example.release.xcconfig"; sourceTree = "<group>"; };
2661CEE1F223361CD1DACC25 /* PNObject.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = PNObject.podspec; path = ../PNObject.podspec; sourceTree = "<group>"; };
3E392C278361604C1602CAF0 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
@ -58,13 +59,12 @@
6003F5B9195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
6003F5BB195388D20070C39A /* Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Tests.m; sourceTree = "<group>"; };
606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = "<group>"; };
808511432137F18DDFE44210 /* Pods_PNObject_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PNObject_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
A90E0E5930707E3F83662328 /* Pods-PNObject_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PNObject_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PNObject_Tests/Pods-PNObject_Tests.debug.xcconfig"; sourceTree = "<group>"; };
C0F786F6B0C2234E3B3A5F30 /* Pods-PNObject_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PNObject_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-PNObject_Tests/Pods-PNObject_Tests.release.xcconfig"; sourceTree = "<group>"; };
C6D958A9E3E6FFB7818A72C7 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
E20844B85780704FB196FA2A /* Pods-PNObject_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PNObject_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PNObject_Example/Pods-PNObject_Example.debug.xcconfig"; sourceTree = "<group>"; };
F74BC1D549B9C619883DB7E0 /* Pods_PNObject_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PNObject_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E7FCF35EF87A5BDD07CA6CD2 /* libPods-PNObject_Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-PNObject_Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -75,7 +75,7 @@
6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */,
6003F592195388D20070C39A /* UIKit.framework in Frameworks */,
6003F58E195388D20070C39A /* Foundation.framework in Frameworks */,
FD9FF8837F786E50B88531C0 /* Pods_PNObject_Example.framework in Frameworks */,
C52729592D50CEDEC002ADC9 /* libPods-PNObject_Example.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -86,7 +86,7 @@
6003F5B0195388D20070C39A /* XCTest.framework in Frameworks */,
6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */,
6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */,
2EC5979E315D48625574D725 /* Pods_PNObject_Tests.framework in Frameworks */,
BCF991672BE36A8FE7F43A6B /* libPods-PNObject_Tests.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -121,8 +121,8 @@
6003F58F195388D20070C39A /* CoreGraphics.framework */,
6003F591195388D20070C39A /* UIKit.framework */,
6003F5AF195388D20070C39A /* XCTest.framework */,
F74BC1D549B9C619883DB7E0 /* Pods_PNObject_Example.framework */,
808511432137F18DDFE44210 /* Pods_PNObject_Tests.framework */,
0ABF8340F735722CEE937FA3 /* libPods-PNObject_Example.a */,
E7FCF35EF87A5BDD07CA6CD2 /* libPods-PNObject_Tests.a */,
);
name = Frameworks;
sourceTree = "<group>";

View File

@ -1,5 +1,3 @@
use_frameworks!
target 'PNObject_Example' do
pod 'PNObject', :path => '../'
pod 'PureLayout'

View File

@ -1,4 +1,6 @@
PODS:
- AeroGear-Crypto (0.2.3):
- libsodium-ios (~> 0.4.5)
- AFNetworking (3.1.0):
- AFNetworking/NSURLSession (= 3.1.0)
- AFNetworking/Reachability (= 3.1.0)
@ -32,14 +34,13 @@ PODS:
- FBSDKCoreKit
- FBSDKShareKit (4.18.0):
- FBSDKCoreKit
- libsodium (1.0.11)
- NAChloride (2.2.1):
- libsodium
- libsodium-ios (0.4.5)
- NSDate_Utils (1.0.0)
- NSString-Helper (1.0.5)
- nv-ios-http-status (0.0.1)
- PEAR-FileManager-iOS (1.3.1)
- PNObject (1.0.1):
- PNObject (1.0.2):
- AeroGear-Crypto
- AFNetworking
- CodFis-Helper
- DDDKeychainWrapper
@ -47,7 +48,6 @@ PODS:
- FBSDKCoreKit
- FBSDKLoginKit
- FBSDKShareKit
- NAChloride
- NSDate_Utils
- NSString-Helper
- nv-ios-http-status
@ -72,6 +72,7 @@ EXTERNAL SOURCES:
:path: "../"
SPEC CHECKSUMS:
AeroGear-Crypto: d97389c7aa9b25360fecd5938f051ab9027d67cc
AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67
Bolts: 8a7995239dbe724f9cba2248b766d48b7ebdd322
CodFis-Helper: 28be4c74d7202542459d72354f59b1215871de87
@ -81,19 +82,18 @@ SPEC CHECKSUMS:
FBSDKCoreKit: 15fef8804a4629f98c6f4e55e81a76c9d725d85e
FBSDKLoginKit: 6773073e970b2b15fb12e451ce7f11da0532b880
FBSDKShareKit: 0b8d6cc3f103c75297eb3c62caec284a2ccf1b9e
libsodium: 9aba161d2ee096977ecbdcce1ada69ffe511970c
NAChloride: 8f3d4f9a20df6b68840789a22a70aa4fcc437b0c
libsodium-ios: c3fc6b66b8c67315710ae0dc4c95e496b4f18533
NSDate_Utils: 45d47afab329001ccafe056308d0cc05460e5298
NSString-Helper: 459e1b6a62b3bf7db10f01b0d102548608e945c4
nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f
PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3
PNObject: 29dddced794646b5f5c59c0654c8211d5e45b18c
PNObject: ef6217847529a71128e2041c2146c7b1410ad20f
PureLayout: 4d550abe49a94f24c2808b9b95db9131685fe4cd
RZDataBinding: 6981e90ddaae2f5e02028323b1043f8c31013109
Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2
StrongestPasswordValidator: 921e42615bdf353513c6f925bffd4fc29865dbd7
UIDevice-Utils: 11c10b18d3c6489b45a97436e5ae6064a3622820
PODFILE CHECKSUM: 57090c7ea88a91b49ca8dd73d9e7c6b866e772ba
PODFILE CHECKSUM: db08ccdd0a68e33d4a1cceb1843643fbab2f2a8e
COCOAPODS: 1.2.0.beta.3

14
Example/Pods/AeroGear-Crypto/LICENSE generated Normal file
View File

@ -0,0 +1,14 @@
JBoss, Home of Professional Open Source
Copyright ${year}, Red Hat, Inc., and individual contributors
by the @authors tag. See the copyright.txt in the distribution for a
full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

117
Example/Pods/AeroGear-Crypto/README.md generated Normal file
View File

@ -0,0 +1,117 @@
# aerogear-crypto-ios [![Build Status](https://travis-ci.org/aerogear/aerogear-crypto-ios.png)](https://travis-ci.org/aerogear/aerogear-crypto-ios)
## Project Aim
_"Crypto for Humans"_
The aim of the project is to provide useful and easy to use API interfaces for performing advanced cryptographic techniques in the iOS platform. Anyone who has tried to use the underlying crypto functionality APIs provided by the iOS, or to integrate with external crypto libraries like OpenSSL, can understand how frustrated the experience can be. The reasons for this are twofold. Firstly, all crypto libraries offer a variety of cryptographic primitives and you need to make a lot of decisions about which specific pieces to use. And if your decisions are wrong, the end-result will be an insecure system. Secondly, most libraries are written using the C language (and for a good reason), but this results in cumbersome usage for an obj-c developer (with potentially adverse and dangerous consequences for the unfamiliar).
By leveraging the state-of-the-art [NaCl](http://nacl.cr.yp.to) encryption library, which provides extremely powerful cryptographic primitives so the developer doesn't need to worry on choosing the "right" one and offering an easy-to-use interfaces around the platform's build-in Security and CommonCrypto services, we believe Crypto can be transformed from a frustrating experience to an enjoyable one.
We understand that applying good cryptographic techniques is not an easy task and requires deep knowledge of the underlying concepts. But we strongly believe a "friendlier" developer interface can ease that pain.
The project shares the same vision with our sibling AeroGear project [AeroGear-Crypto-Java](https://github.com/aerogear/aerogear-crypto-java). If you are a Java developer, we strongly recommend to look at the project.
The project is also the base for providing cryptographic services to [AeroGear-IOS](http://www.aerogear.org) library project.
## Requirements
* iOS 7 or higher
### Installation with CocoaPods
[CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which eases the pain of installing third-party libraries in your programs. The project is already published in the Cocoapods repository, so just add the following line in your _'Podfile'_ :
#### Podfile
```
pod "AeroGear-Crypto", '0.2.3'
```
## Project Status
The following services are currently provided:
* A [Symmetric encryption](http://nacl.cr.yp.to/secretbox.html) interface
* An [Asymmetric encryption interface](http://nacl.cr.yp.to/box.html)
* Password based key generation using [PBKDF2](http://en.wikipedia.org/wiki/PBKDF2)
* Generation of Cryptographically secure [random numbers](http://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator).
* [Digital signatures](http://ed25519.cr.yp.to) support interface
* [Hashing functions](http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf) interface
## Getting started
### Password based key derivation
AGPBKDF2 *pbkdf2 = [[AGPBKDF2 alloc] init];
NSData *rawKey = [pbkdf2 deriveKey:@"passphrase"];
### Symmetric encryption
//Generate the key
AGPBKDF2 *pbkdf2 = [[AGPBKDF2 alloc] init];
NSData *privateKey = [pbkdf2 deriveKey:@"passphrase"];
//Initializes the secret box
AGSecretBox *secretBox = [[AGSecretBox alloc] initWithKey:privateKey];
//Encryption
NSData *nonce = [AGRandomGenerator randomBytes:32];
NSData *dataToEncrypt = [@"My bonnie lies over the ocean" dataUsingEncoding:NSUTF8StringEncoding];
NSData *cipherData = [secretBox encrypt:dataToEncrypt nonce:nonce];
//Decryption
AGSecretBox *pandora = [[AGSecretBox alloc] initWithKey:privateKey];
NSData *message = [secretBox decrypt:cipherData nonce:nonce];
### Asymmetric encryption
//Create a new key pair
AGKeyPair *keyPairBob = [[AGKeyPair alloc] init];
AGKeyPair *keyPairAlice = [[AGKeyPair alloc] init];
//Initializes the crypto box
AGCryptoBox *cryptoBox = [[AGCryptoBox alloc] initWithKey:keyPairAlice.publicKey privateKey:keyPairBob.privateKey];
NSData *nonce = [AGRandomGenerator randomBytes:32];
NSData *dataToEncrypt = [@"My bonnie lies over the ocean" dataUsingEncoding:NSUTF8StringEncoding];
NSData *cipherData = [cryptoBox encrypt:dataToEncrypt nonce:nonce];
//Create a new box to test end to end asymmetric encryption
AGCryptoBox *pandora = [[AGCryptoBox alloc] initWithKey:keyPairBob.publicKey privateKey:keyPairAlice.privateKey];
NSData *message = [pandora decrypt:cipherData nonce:nonce];
### Hashing functions
// create an SHA256 hash
AGHash *agHash = [[AGHash alloc] init:CC_SHA256_DIGEST_LENGTH];
NSData *rawPassword = [agHash digest:@"My bonnie lies over the ocean"];
// create an SHA512 hash
AGHash *agHash = [[AGHash alloc] init:CC_SHA512_DIGEST_LENGTH];
NSData *rawPassword = [agHash digest:@"My bonnie lies over the ocean"];
### Digital Signatures
NSData *message = [@"My bonnie lies over the ocean" dataUsingEncoding:NSUTF8StringEncoding];
AGSigningKey *signingKey = [[AGSigningKey alloc] init];
AGVerifyKey *verifyKey = [[AGVerifyKey alloc] initWithKey:signingKey.publicKey];
// sign the message
NSData *signedMessage = [signingKey sign:message];
// should detect corrupted signature
NSMutableData *corruptedSignature = [NSMutableData dataWithLength:64];
BOOL isValid = [verifyKey verify:message signature:signedMessage];
// isValid should be YES
BOOL isValid = [verifyKey verify:message signature:corruptedSignature];
// isValid should be NO
### Generation of Cryptographically secure Random Numbers
NSData *random = [AGRandomGenerator randomBytes:<length>];
## Join us
On-going work is tracked on project's [JIRA]((https://issues.jboss.org/browse/AGIOS) issue tracker as well as on our [mailing list](https://lists.jboss.org/mailman/listinfo/aerogear-dev). You can also find the developers hanging on [IRC](irc://irc.freenode.net/aerogear), feel free to join in the discussions. We want your feedback!

View File

@ -0,0 +1,72 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
#import <libsodium-ios/sodium/crypto_box_curve25519xsalsa20poly1305.h>
#import "AGKeyPair.h"
/**
* Provide public key authenticated encryption via curve25519xsalsa20poly1305
* (see http://nacl.cr.yp.to/box.html)
*/
@interface AGCryptoBox : NSObject
@property(readonly, nonatomic, strong) NSData *privateKey;
@property(readonly, nonatomic, strong) NSData *publicKey;
/**
* Crypto box default initialization
*
* @param keyPair containig public and private keys provided.
*
* @return the AGCryptoBox object.
*/
- (id)initWithKeyPair:(AGKeyPair *)keyPair;
/**
* Crypto box initialization
*
* @param publicKey the public encryption key provided.
* @param privateKey the private encryption key provided.
*
* @return the AGCryptoBox object.
*/
- (id)initWithKey:(NSData *)publicKey privateKey:(NSData *)privateKey;
/**
* Encrypts and authenticates the data object provided given a nonce.
*
* @param data The data object to encrypt.
* @param nonce the cryptographically secure pseudorandom number.
* @param error If an error occurs, upon return contains an `NSError` object that describes the problem.
*
* @return An NSData object that holds the encrypted(cipher) data.
*/
- (NSData *)encrypt:(NSData *)data nonce:(NSData *)nonce error:(NSError * __autoreleasing *)error;
/**
* Decrypts the data object provided given a nonce.
*
* @param data The data object(cipher) to decrypt.
* @param nonce The cryptographically secure pseudorandom number.
* @param error If an error occurs, upon return contains an `NSError` object that describes the problem.
*
* @return An NSData object that holds the decrypted data.
*/
- (NSData *)decrypt:(NSData *)data nonce:(NSData *)nonce error:(NSError * __autoreleasing *)error;
@end

View File

@ -0,0 +1,96 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "AGCryptoBox.h"
#import "AGUtil.h"
@implementation AGCryptoBox
- (id)initWithKeyPair:(AGKeyPair *)keyPair {
return [self initWithKey:keyPair.publicKey privateKey:keyPair.privateKey];
}
- (id)initWithKey:(NSData *)publicKey privateKey:(NSData *)privateKey {
NSParameterAssert(privateKey != nil && [privateKey length] == crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES);
NSParameterAssert(publicKey != nil && [publicKey length] == crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES);
self = [super init];
if (self) {
_privateKey = privateKey;
_publicKey = publicKey;
}
return self;
}
- (NSData *)encrypt:(NSData *)data nonce:(NSData *)nonce error:(NSError * __autoreleasing *)error {
NSParameterAssert(data != nil);
NSParameterAssert(nonce != nil && [nonce length] == crypto_box_curve25519xsalsa20poly1305_NONCEBYTES);
NSData *msg = [AGUtil prependZeros:crypto_box_curve25519xsalsa20poly1305_ZEROBYTES msg:data];
NSMutableData *ct = [[NSMutableData alloc] initWithLength:msg.length];
int status = crypto_box_curve25519xsalsa20poly1305(
[ct mutableBytes],
[msg bytes],
msg.length,
[nonce bytes],
[_publicKey bytes],
[_privateKey bytes]);
if (status != 0) {
if (error) {
NSDictionary *userInfo = @{NSLocalizedDescriptionKey:
[NSString stringWithFormat:@"failed to encrypt data provided, NaCl error: %d", status]};
*error = [NSError errorWithDomain:AGCryptoErrorDomain code:AGCryptoFailedToEncryptError userInfo:userInfo];
}
return nil;
}
return [ct subdataWithRange:NSMakeRange(crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES,
ct.length - crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES)];
}
- (NSData *)decrypt:(NSData *)data nonce:(NSData *)nonce error:(NSError * __autoreleasing *)error {
NSParameterAssert(data != nil);
NSParameterAssert(nonce != nil && [nonce length] == crypto_box_curve25519xsalsa20poly1305_NONCEBYTES);
NSData *ct = [AGUtil prependZeros:crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES msg:data];
NSMutableData *message = [[NSMutableData alloc] initWithLength:ct.length];
int status = crypto_box_curve25519xsalsa20poly1305_open(
[message mutableBytes],
[ct bytes],
message.length,
[nonce bytes],
[_publicKey bytes],
[_privateKey bytes]);
if (status != 0) {
if (error) {
NSDictionary *userInfo = @{NSLocalizedDescriptionKey:
[NSString stringWithFormat:@"failed to decrypt data provided, NaCl error: %d", status]};
*error = [NSError errorWithDomain:AGCryptoErrorDomain code:AGCryptoFailedToDecryptError userInfo:userInfo];
}
return nil;
}
return [message subdataWithRange:NSMakeRange(crypto_box_curve25519xsalsa20poly1305_ZEROBYTES,
message.length - crypto_box_curve25519xsalsa20poly1305_ZEROBYTES)];
}
@end

View File

@ -0,0 +1,43 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
/**
* Class that create a message digest using SHA2 hash function
* (see http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf)
*/
@interface AGHash : NSObject
/**
* Initialize with the Hash function provided.
*
* @param algorithm The length of hash function e.g. CC_SHA512_DIGEST_LENGTH or CC_SHA256_DIGEST_LENGTH
*
* @return The AGHash object.
*/
- (id)init:(char)algorithm;
/**
* Create a message digest based on the string provided.
*
* @param str The raw text.
*
* @return an NSData object containing the message digest.
*/
- (NSData *)digest:(NSString *)str;
@end

View File

@ -0,0 +1,57 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <CommonCrypto/CommonDigest.h>
#import "AGHash.h"
@implementation AGHash {
unsigned char _algorithm;
}
- (id)init:(char)algorithm {
self = [super init];
if (self) {
_algorithm = algorithm;
}
return self;
}
- (id)init {
self = [super init];
if (self) {
_algorithm = CC_SHA256_DIGEST_LENGTH;
}
return self;
}
- (NSData *)digest:(NSString *)str {
NSData *dataIn = [str dataUsingEncoding:NSUTF8StringEncoding];
NSMutableData *hash = [NSMutableData dataWithLength:_algorithm];
if (_algorithm == CC_SHA512_DIGEST_LENGTH ) {
CC_SHA512(dataIn.bytes, (CC_LONG)dataIn.length, hash.mutableBytes);
} else {
CC_SHA256(dataIn.bytes, (CC_LONG)dataIn.length, hash.mutableBytes);
}
return hash;
}
@end

View File

@ -0,0 +1,30 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
#import <libsodium-ios/sodium/crypto_box_curve25519xsalsa20poly1305.h>
/**
* Represents a pair of cryptographic keys (a public and a private key) used for asymmetric encryption
*/
@interface AGKeyPair : NSObject
@property(readonly, nonatomic, strong) NSData *privateKey;
@property(readonly, nonatomic, strong) NSData *publicKey;
- (id)initWithPrivateKey:(NSData *)privateKey publicKey:(NSData *)publicKey;
@end

View File

@ -0,0 +1,42 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "AGKeyPair.h"
@implementation AGKeyPair
- (id)initWithPrivateKey:(NSData *)privateKey publicKey:(NSData *)publicKey {
self = [super init];
if (self) {
_publicKey = publicKey;
_privateKey = privateKey;
}
return self;
}
- (id)init {
NSMutableData *publicKey = [NSMutableData dataWithLength:crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES];
NSMutableData *privateKey = [NSMutableData dataWithLength:crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES];
//Generate the keypair
crypto_box_curve25519xsalsa20poly1305_keypair([publicKey mutableBytes], [privateKey mutableBytes]);
return [self initWithPrivateKey:privateKey publicKey:publicKey];
}
@end

View File

@ -0,0 +1,72 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
// constants used by PBKDF2 algorithm.
extern const NSUInteger AGPBKDF2Iterations;
extern const NSUInteger AGPBKDF2MinimumIterations;
extern const NSUInteger AGPBKDF2DerivedKeyLength;
extern const NSUInteger AGPBKDF2MinimumSaltLength;
/**
* Class that derives a key from a text password/passphrase using
* the PBKDF2 algorithm provided by CommonCrypto.
* (see http://en.wikipedia.org/wiki/PBKDF2)
*/
@interface AGPBKDF2 : NSObject
/**
* Derive a key from text password/passphrase.
*
* @param password The password/passphrase to use for key derivation.
*
* @return an NSData object containing the derived key.
*/
- (NSData *)deriveKey:(NSString *)password;
/**
* Derive a key from text password/passphrase.
*
* @param password The password/passphrase to use for key derivation.
* @param salt A randomly chosen value used used during key derivation.
*
* @return an NSData object containing the derived key.
*/
- (NSData *)deriveKey:(NSString *)password salt:(NSData *)salt;
/**
* Derive a key from text password/passphrase.
*
* @param password The password/passphrase to use for key derivation.
* @param salt A randomly chosen value used used during key derivation.
* @param iterations The number of iterations against the cryptographic hash.
*
* @return an NSData object containing the derived key.
*/
- (NSData *)deriveKey:(NSString *)password salt:(NSData *)salt iterations:(NSUInteger)iterations;
- (BOOL)validate:(NSString *)password encryptedPassword:(NSData *)encryptedPassword salt:(NSData *)salt;
/**
* Returns the salt used for the key derivation
*
* @return an NSData object containing the salt
*/
- (NSData *)salt;
@end

View File

@ -0,0 +1,76 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "AGPBKDF2.h"
#import "AGRandomGenerator.h"
#import <CommonCrypto/CommonCryptor.h>
#import <CommonCrypto/CommonKeyDerivation.h>
const NSUInteger AGPBKDF2Iterations = 20000;
const NSUInteger AGPBKDF2MinimumIterations = 10000;
const NSUInteger AGPBKDF2DerivedKeyLength = 32;
const NSUInteger AGPBKDF2MinimumSaltLength = 16;
@implementation AGPBKDF2 {
NSData *_salt;
}
- (NSData *)deriveKey:(NSString *)password {
return [self deriveKey:password salt:[AGRandomGenerator randomBytes]];
}
- (NSData *)deriveKey:(NSString *)password salt:(NSData *)salt {
return [self deriveKey:password salt:salt iterations:AGPBKDF2Iterations];
}
- (NSData *)deriveKey:(NSString *)password salt:(NSData *)salt iterations:(NSUInteger)iterations {
NSParameterAssert(password != nil);
NSParameterAssert(salt != nil && [salt length] >= AGPBKDF2MinimumSaltLength);
NSParameterAssert(iterations >= AGPBKDF2MinimumIterations);
_salt = salt;
NSMutableData *key = [NSMutableData dataWithLength:AGPBKDF2DerivedKeyLength];
int result = CCKeyDerivationPBKDF(kCCPBKDF2,
[password UTF8String],
[password length],
[salt bytes],
[salt length],
kCCPRFHmacAlgSHA1,
(uint)iterations,
[key mutableBytes],
AGPBKDF2DerivedKeyLength);
if (result == kCCParamError) {
return nil;
}
return key;
}
- (BOOL)validate:(NSString *)password encryptedPassword:(NSData *)encryptedPassword salt:(NSData *)salt {
NSData *attempt = [self deriveKey:password salt:salt];
return [encryptedPassword isEqual:attempt];
}
- (NSData *)salt {
return _salt;
}
@end

View File

@ -0,0 +1,41 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
/**
* Utility class for random generation of cryptographically secure random numbers.
*/
@interface AGRandomGenerator : NSObject
/**
* Generate secure random numbers with default size of 16 bytes.
*
* @return an NSData object filled with random bytes.
*/
+ (NSData *)randomBytes;
/**
* Generate secure random numbers with length bytes.
*
* @param length The length of the random bytes to generate.
*
* @return an NSData object filled with random bytes.
*/
+ (NSData *)randomBytes:(size_t)length;
@end

View File

@ -0,0 +1,34 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "AGRandomGenerator.h"
@implementation AGRandomGenerator
+ (NSData *)randomBytes {
return [self randomBytes:16];
}
+ (NSData *)randomBytes:(size_t)length {
NSMutableData *data = [NSMutableData dataWithLength:length];
int res = SecRandomCopyBytes(kSecRandomDefault, length, [data mutableBytes]);
return (res == noErr? data: nil);
}
@end

View File

@ -0,0 +1,58 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
#import <libsodium-ios/sodium/crypto_secretbox_xsalsa20poly1305.h>
/**
* Provide symmetric key authenticated encryption via xsalsa20poly1305
* (see http://nacl.cr.yp.to/secretbox.html)
*/
@interface AGSecretBox : NSObject
/**
* Secret box default initialization
*
* @param key the private encryption key provided.
*
* @return the AGSecretBox object.
*/
- (id)initWithKey:(NSData *)key;
/**
* Encrypts and authenticates the data object provided given a nonce.
*
* @param data The data object to encrypt.
* @param nonce the cryptographically secure pseudorandom number.
* @param error If an error occurs, upon return contains an `NSError` object that describes the problem.
*
* @return An NSData object that holds the encrypted(cipher) data.
*/
- (NSData *)encrypt:(NSData *)data nonce:(NSData *)nonce error:(NSError * __autoreleasing *)error;
/**
* Decrypts the data object provided given a nonce.
*
* @param data The data object(cipher) to decrypt.
* @param nonce The cryptographically secure pseudorandom number.
* @param error If an error occurs, upon return contains an `NSError` object that describes the problem.
*
* @return An NSData object that holds the decrypted data.
*/
- (NSData *)decrypt:(NSData *)data nonce:(NSData *)nonce error:(NSError * __autoreleasing *)error;
@end

View File

@ -0,0 +1,92 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "AGSecretBox.h"
#import "AGUtil.h"
@implementation AGSecretBox {
NSData *_key;
}
- (id)initWithKey:(NSData *)key {
NSParameterAssert(key != nil && [key length] == crypto_secretbox_xsalsa20poly1305_KEYBYTES);
self = [super init];
if (self) {
_key = key;
}
return self;
}
- (NSData *)encrypt:(NSData *)data nonce:(NSData *)nonce error:(NSError * __autoreleasing *)error {
NSParameterAssert(data != nil);
NSParameterAssert(nonce != nil && [nonce length] == crypto_secretbox_xsalsa20poly1305_NONCEBYTES);
NSData *msg = [AGUtil prependZeros:crypto_secretbox_xsalsa20poly1305_ZEROBYTES msg:data];
NSMutableData *ct = [[NSMutableData alloc] initWithLength:msg.length];
int status = crypto_secretbox_xsalsa20poly1305(
[ct mutableBytes],
[msg bytes],
msg.length,
[nonce bytes],
[_key bytes]);
if (status != 0) {
if (error) {
NSDictionary *userInfo = @{NSLocalizedDescriptionKey:
[NSString stringWithFormat:@"failed to encrypt data provided, NaCl error: %d", status]};
*error = [NSError errorWithDomain:AGCryptoErrorDomain code:AGCryptoFailedToEncryptError userInfo:userInfo];
}
return nil;
}
return [ct subdataWithRange:NSMakeRange(crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES,
ct.length - crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES)];
}
- (NSData *)decrypt:(NSData *)data nonce:(NSData *)nonce error:(NSError * __autoreleasing *)error {
NSParameterAssert(data != nil);
NSParameterAssert(nonce != nil && [nonce length] == crypto_secretbox_xsalsa20poly1305_NONCEBYTES);
NSData *ct = [AGUtil prependZeros:crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES msg:data];
NSMutableData *message = [[NSMutableData alloc] initWithLength:ct.length];
int status = crypto_secretbox_xsalsa20poly1305_open(
[message mutableBytes],
[ct bytes],
message.length,
[nonce bytes],
[_key bytes]);
if (status != 0) {
if (error) {
NSDictionary *userInfo = @{NSLocalizedDescriptionKey:
[NSString stringWithFormat:@"failed to decrypt data provided, NaCl error: %d", status]};
*error = [NSError errorWithDomain:AGCryptoErrorDomain code:AGCryptoFailedToDecryptError userInfo:userInfo];
}
return nil;
}
return [message subdataWithRange:NSMakeRange(crypto_secretbox_xsalsa20poly1305_ZEROBYTES,
message.length - crypto_secretbox_xsalsa20poly1305_ZEROBYTES)];
}
@end

View File

@ -0,0 +1,40 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
#import <libsodium-ios/sodium/crypto_sign_ed25519.h>
#import <libsodium-ios/sodium/randombytes.h>
/**
* Create digital signatures
* (see http://ed25519.cr.yp.to)
*/
@interface AGSigningKey : NSObject
@property(readonly, nonatomic, strong) NSData *secretKey;
@property(readonly, nonatomic, strong) NSData *publicKey;
/**
* Digitally sign a message to prevent against tampering and forgery.
*
* @param message The message to be signed.
*
* @return An NSData object that holds the signed message.
*/
- (NSData *)sign:(NSData *)message;
@end

View File

@ -0,0 +1,64 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "AGSigningKey.h"
#import "AGUtil.h"
@implementation AGSigningKey {
NSMutableData *_secretKey;
NSMutableData *_publicKey;
}
- (id)init {
self = [super init];
if (self) {
NSMutableData *seed = [NSMutableData dataWithLength:crypto_sign_ed25519_SECRETKEYBYTES];
randombytes([seed mutableBytes], [seed length]);
_publicKey = [NSMutableData dataWithLength:crypto_sign_ed25519_PUBLICKEYBYTES];
_secretKey = [NSMutableData dataWithLength:crypto_sign_ed25519_SECRETKEYBYTES];
// Generate the keypair
int status = crypto_sign_ed25519_seed_keypair([_publicKey mutableBytes],
[_secretKey mutableBytes],
[seed mutableBytes]);
// should not happen
NSAssert(status == 0, @"Failed to generate a key pair", status);
}
return self;
}
- (NSData *)sign:(NSData *)message {
NSParameterAssert(message != nil);
NSMutableData *signature = [AGUtil prependZeros:crypto_sign_ed25519_BYTES msg:message];
unsigned long long bufferLen;
// sign the message
int status = crypto_sign_ed25519([signature mutableBytes], &bufferLen,
[message bytes],
[message length],
[_secretKey bytes]);
NSAssert(status == 0, @"unable to sign message", status);
return [signature subdataWithRange:NSMakeRange(0, crypto_sign_ed25519_BYTES)];
}
@end

View File

@ -0,0 +1,61 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
#import <libsodium-ios/sodium/crypto_box_curve25519xsalsa20poly1305.h>
typedef NS_ENUM(NSInteger, AGCryptoErrorCodes) {
AGCryptoFailedToEncryptError = -101,
AGCryptoFailedToDecryptError = -102
};
extern NSString * const AGCryptoErrorDomain;
/**
* Utility class for cryptographic operations
*/
@interface AGUtil : NSObject
/**
* Append zeros to the message provided.
*
* @param n Number of zeros.
* @param message The provided message.
*
* @return An NSData object that holds the result.
*/
+ (NSMutableData *)prependZeros:(NSUInteger)n msg:(NSData *)message;
/**
* Convert the provided data to hex.
*
* @param data The NSData to be converted to hex representation.
*
* @return An NSString object with the result of the conversion.
*/
+ (NSString *)hexString:(NSData *)data;
/**
* Convert the provided hex string to bytes.
*
* @param data The hex string to be converted.
*
* @return An NSData object with the result of the conversion.
*/
+ (NSData *)hexStringToBytes:(NSString *)data;
@end

View File

@ -0,0 +1,56 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "AGUtil.h"
NSString * const AGCryptoErrorDomain = @"AGCryptoErrorDomain";
@implementation AGUtil
+ (NSMutableData *)prependZeros:(NSUInteger)n msg:(NSData *)message {
NSMutableData *data = [NSMutableData dataWithLength:n+message.length];
[data replaceBytesInRange:NSMakeRange(n, message.length) withBytes:[message bytes]];
return data;
}
+ (NSString *)hexString:(NSData *)data {
NSMutableString *stringBuffer = [NSMutableString stringWithCapacity:([data length] * 2)];
const unsigned char *dataBuffer = [data bytes];
for (int i = 0; i < [data length]; ++i) {
[stringBuffer appendFormat:@"%02X", dataBuffer[i]];
}
return stringBuffer;
}
+ (NSData *)hexStringToBytes:(NSString *)hex {
NSMutableData *buffer = [NSMutableData data];
unsigned int intValue;
for (int i = 0; i + 2 <= [hex length]; i += 2) {
NSRange range = NSMakeRange(i, 2);
NSString * hexString = [hex substringWithRange:range];
NSScanner * scanner = [NSScanner scannerWithString:hexString];
[scanner scanHexInt:&intValue];
[buffer appendBytes:&intValue length:1];
}
return buffer;
}
@end

View File

@ -0,0 +1,45 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
/**
* Verify digital signatures
* (see http://ed25519.cr.yp.to)
*/
@interface AGVerifyKey : NSObject
/**
* Initialize with the public key provided.
*
* @param key The Public key.
* @return the AGVerifyKey object.
*/
- (id)initWithKey:(NSData *)key;
/**
* Verify the integrity of the message with the signature provided.
*
* @param message The message to be verified.
* @param signature The provided signature.
*
* @return the result of the verification process.
*/
- (BOOL)verify:(NSData *)message signature:(NSData *)signature;
@end

View File

@ -0,0 +1,63 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "AGVerifyKey.h"
#import "AGUtil.h"
#import <libsodium-ios/sodium/crypto_sign_ed25519.h>
@implementation AGVerifyKey {
NSData *_key;
}
- (id)initWithKey:(NSData *)key {
NSParameterAssert(key != nil && [key length] == crypto_sign_ed25519_PUBLICKEYBYTES);
self = [super init];
if (self) {
_key = key;
}
return self;
}
- (BOOL)verify:(NSData *)message signature:(NSData *)signature {
NSParameterAssert(message != nil);
NSParameterAssert(signature != nil && [signature length] == crypto_sign_ed25519_BYTES);
NSMutableData *signAndMsg = [NSMutableData data];
[signAndMsg appendData:signature];
[signAndMsg appendData:message];
unsigned long long bufferLen;
NSMutableData *newBuffer = [[NSMutableData alloc] initWithLength:signAndMsg.length];
int status = crypto_sign_ed25519_open([newBuffer mutableBytes],
&bufferLen,
[signAndMsg bytes],
signAndMsg.length,
[_key bytes]);
if( status != 0 ) {
NSLog(@"Invalid signature %i", status);
return NO;
}
return YES;
}
@end

View File

@ -0,0 +1,32 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _AEROGEARCRYPTO_
#define _AEROGEARCRYPTO_
// imports
#import "AGPBKDF2.h"
#import "AGRandomGenerator.h"
#import "AGSecretBox.h"
#import "AGCryptoBox.h"
#import "AGHash.h"
#import "AGSigningKey.h"
#import "AGVerifyKey.h"
#import "AGKeyPair.h"
#import "AGUtil.h"
#endif /* _AEROGEARCRYPTO_ */

View File

@ -0,0 +1 @@
../../../AFNetworking/UIKit+AFNetworking/AFAutoPurgingImageCache.h

View File

@ -0,0 +1 @@
../../../AFNetworking/AFNetworking/AFHTTPSessionManager.h

View File

@ -0,0 +1 @@
../../../AFNetworking/UIKit+AFNetworking/AFImageDownloader.h

View File

@ -0,0 +1 @@
../../../AFNetworking/UIKit+AFNetworking/AFNetworkActivityIndicatorManager.h

View File

@ -0,0 +1 @@
../../../AFNetworking/AFNetworking/AFNetworkReachabilityManager.h

View File

@ -0,0 +1 @@
../../../AFNetworking/AFNetworking/AFNetworking.h

View File

@ -0,0 +1 @@
../../../AFNetworking/AFNetworking/AFSecurityPolicy.h

View File

@ -0,0 +1 @@
../../../AFNetworking/AFNetworking/AFURLRequestSerialization.h

View File

@ -0,0 +1 @@
../../../AFNetworking/AFNetworking/AFURLResponseSerialization.h

View File

@ -0,0 +1 @@
../../../AFNetworking/AFNetworking/AFURLSessionManager.h

View File

@ -0,0 +1 @@
../../../AFNetworking/UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.h

View File

@ -0,0 +1 @@
../../../AFNetworking/UIKit+AFNetworking/UIButton+AFNetworking.h

View File

@ -0,0 +1 @@
../../../AFNetworking/UIKit+AFNetworking/UIImage+AFNetworking.h

View File

@ -0,0 +1 @@
../../../AFNetworking/UIKit+AFNetworking/UIImageView+AFNetworking.h

View File

@ -0,0 +1 @@
../../../AFNetworking/UIKit+AFNetworking/UIKit+AFNetworking.h

View File

@ -0,0 +1 @@
../../../AFNetworking/UIKit+AFNetworking/UIProgressView+AFNetworking.h

View File

@ -0,0 +1 @@
../../../AFNetworking/UIKit+AFNetworking/UIRefreshControl+AFNetworking.h

View File

@ -0,0 +1 @@
../../../AFNetworking/UIKit+AFNetworking/UIWebView+AFNetworking.h

View File

@ -0,0 +1 @@
../../../AeroGear-Crypto/crypto-sdk/AGCryptoBox.h

View File

@ -0,0 +1 @@
../../../AeroGear-Crypto/crypto-sdk/AGHash.h

View File

@ -0,0 +1 @@
../../../AeroGear-Crypto/crypto-sdk/AGKeyPair.h

View File

@ -0,0 +1 @@
../../../AeroGear-Crypto/crypto-sdk/AGPBKDF2.h

View File

@ -0,0 +1 @@
../../../AeroGear-Crypto/crypto-sdk/AGRandomGenerator.h

View File

@ -0,0 +1 @@
../../../AeroGear-Crypto/crypto-sdk/AGSecretBox.h

View File

@ -0,0 +1 @@
../../../AeroGear-Crypto/crypto-sdk/AGSigningKey.h

View File

@ -0,0 +1 @@
../../../AeroGear-Crypto/crypto-sdk/AGUtil.h

View File

@ -0,0 +1 @@
../../../AeroGear-Crypto/crypto-sdk/AGVerifyKey.h

View File

@ -0,0 +1 @@
../../../AeroGear-Crypto/crypto-sdk/AeroGearCrypto.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/iOS/BFAppLink.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/iOS/BFAppLinkNavigation.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/iOS/BFAppLinkResolving.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/iOS/BFAppLinkReturnToRefererController.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/iOS/BFAppLinkReturnToRefererView.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/iOS/Internal/BFAppLinkReturnToRefererView_Internal.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/iOS/BFAppLinkTarget.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/iOS/Internal/BFAppLink_Internal.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/Common/BFCancellationToken.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/Common/BFCancellationTokenRegistration.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/Common/BFCancellationTokenSource.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/Common/BFExecutor.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/iOS/BFMeasurementEvent.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/iOS/Internal/BFMeasurementEvent_Internal.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/Common/BFTask+Exceptions.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/Common/BFTask.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/Common/BFTaskCompletionSource.h

1
Example/Pods/Headers/Private/Bolts/BFURL.h generated Symbolic link
View File

@ -0,0 +1 @@
../../../Bolts/Bolts/iOS/BFURL.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/iOS/Internal/BFURL_Internal.h

View File

@ -0,0 +1 @@
../../../Bolts/Bolts/iOS/BFWebViewAppLinkResolver.h

1
Example/Pods/Headers/Private/Bolts/Bolts.h generated Symbolic link
View File

@ -0,0 +1 @@
../../../Bolts/Bolts/Common/Bolts.h

View File

@ -0,0 +1 @@
../../../CodFis-Helper/CodFis-Helper/CodFis+Helper.h

View File

@ -0,0 +1 @@
../../../CodFis-Helper/CodFis-Helper/CodFisResponse.h

View File

@ -0,0 +1 @@
../../../CodFis-Helper/CodFis-Helper/ResponseConstants.h

View File

@ -0,0 +1 @@
../../../CodFis-Helper/CodFis-Helper/VatNumber+Helper.h

View File

@ -0,0 +1 @@
../../../DDDKeychainWrapper/Pod/Classes/DDDKeychainWrapper.h

View File

@ -0,0 +1 @@
../../../DJLocalization/DJLocalization/DJLocalizableString.h

View File

@ -0,0 +1 @@
../../../DJLocalization/DJLocalization/DJLocalization.h

View File

@ -0,0 +1 @@
../../../DJLocalization/DJLocalization/DJLocalizationSystem+Private.h

View File

@ -0,0 +1 @@
../../../DJLocalization/DJLocalization/DJLocalizationSystem.h

View File

@ -0,0 +1 @@
../../../DJLocalization/DJLocalization/UIStoryboard+DJLocalization.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/EXPBlockDefinedMatcher.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/EXPDefines.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/EXPDoubleTuple.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/EXPExpect.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/EXPFloatTuple.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/EXPMatcher.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/Matchers/EXPMatcherHelpers.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/Matchers/EXPMatchers+beCloseTo.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/Matchers/EXPMatchers+beFalsy.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/Matchers/EXPMatchers+beGreaterThan.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/Matchers/EXPMatchers+beGreaterThanOrEqualTo.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/Matchers/EXPMatchers+beIdenticalTo.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/Matchers/EXPMatchers+beInTheRangeOf.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/Matchers/EXPMatchers+beInstanceOf.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/Matchers/EXPMatchers+beKindOf.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/Matchers/EXPMatchers+beLessThan.h

View File

@ -0,0 +1 @@
../../../Expecta/Expecta/Matchers/EXPMatchers+beLessThanOrEqualTo.h

Some files were not shown because too many files have changed in this diff Show More