37 lines
1.0 KiB
Objective-C
37 lines
1.0 KiB
Objective-C
//
|
|
// GCDWebServerDataResponse+Crypto.m
|
|
// kordophoned
|
|
//
|
|
// Created by James Magahern on 11/15/18.
|
|
// Copyright © 2018 James Magahern. All rights reserved.
|
|
//
|
|
|
|
#import "GCDWebServerDataResponse+Crypto.h"
|
|
|
|
#import "NSData+AES.h"
|
|
|
|
// TEMP!!
|
|
static NSString *const kSymmetricKey = @"axPy0nljtG/TOVJSVwVXag==";
|
|
|
|
@implementation GCDWebServerDataResponse (Crypto)
|
|
|
|
+ (nullable instancetype)encryptedResponseWithJSONObject:(id)object
|
|
{
|
|
NSData *data = [NSJSONSerialization dataWithJSONObject:object options:0 error:NULL];
|
|
if (data == nil) {
|
|
return nil;
|
|
}
|
|
|
|
NSError *error = nil;
|
|
NSData *ivData = [[[NSUUID UUID] UUIDString] dataUsingEncoding:NSUTF8StringEncoding];
|
|
NSData *keyData = [[NSData alloc] initWithBase64EncodedString:kSymmetricKey options:0];
|
|
NSData *encryptedData = [data encryptedDataWithKey:keyData iv:ivData error:&error];
|
|
if (error) {
|
|
NSLog(@"Error encrypting response: %@", error);
|
|
}
|
|
|
|
return [[self alloc] initWithData:encryptedData contentType:@"application/octet-stream"];
|
|
}
|
|
|
|
@end
|