Some basic crypto laid down and tests
This commit is contained in:
48
Tests/CryptoTests.m
Normal file
48
Tests/CryptoTests.m
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Tests.m
|
||||
// Tests
|
||||
//
|
||||
// Created by James Magahern on 11/15/18.
|
||||
// Copyright © 2018 James Magahern. All rights reserved.
|
||||
//
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "NSData+AES.h"
|
||||
|
||||
// base64 encoded
|
||||
static NSString *const kTestKey = @"QMeDmiHj8eCFVfrQWQfDpw==";
|
||||
|
||||
@interface Tests : XCTestCase
|
||||
@property (nonatomic, strong) NSString *commonPayload;
|
||||
@property (nonatomic, strong) NSData *commonIVData;
|
||||
@property (nonatomic, strong) NSData *symmetricKeyData;
|
||||
@end
|
||||
|
||||
@implementation Tests
|
||||
|
||||
- (void)setUp {
|
||||
self.commonPayload = @"Hey this is a test";
|
||||
|
||||
NSString *IVDataString = [[NSUUID UUID] UUIDString];
|
||||
self.commonIVData = [IVDataString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
self.symmetricKeyData = [[NSData alloc] initWithBase64EncodedString:kTestKey options:0];
|
||||
XCTAssert(self.commonIVData && self.symmetricKeyData);
|
||||
}
|
||||
|
||||
- (void)testEncryptionAndDecryption
|
||||
{
|
||||
NSData *inputData = [self.commonPayload dataUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
NSError *error = nil;
|
||||
NSData *encryptedData = [inputData encryptedDataWithKey:self.symmetricKeyData iv:self.commonIVData error:&error];
|
||||
XCTAssert(!error);
|
||||
|
||||
NSData *decryptedData = [encryptedData decryptedDataWithKey:self.symmetricKeyData iv:self.commonIVData error:&error];
|
||||
XCTAssert(!error);
|
||||
|
||||
XCTAssert([decryptedData isEqualToData:inputData]);
|
||||
}
|
||||
|
||||
@end
|
||||
22
Tests/Info.plist
Normal file
22
Tests/Info.plist
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
||||
Reference in New Issue
Block a user