Encrypted server response
This commit is contained in:
20
kordophone/Crypto/GCDWebServerDataResponse+Crypto.h
Normal file
20
kordophone/Crypto/GCDWebServerDataResponse+Crypto.h
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// GCDWebServerDataResponse+Crypto.h
|
||||
// kordophoned
|
||||
//
|
||||
// Created by James Magahern on 11/15/18.
|
||||
// Copyright © 2018 James Magahern. All rights reserved.
|
||||
//
|
||||
|
||||
#import <GCDWebServers/GCDWebServers.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface GCDWebServerDataResponse (Crypto)
|
||||
|
||||
+ (nullable instancetype)encryptedResponseWithJSONObject:(id)object;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
36
kordophone/Crypto/GCDWebServerDataResponse+Crypto.m
Normal file
36
kordophone/Crypto/GCDWebServerDataResponse+Crypto.m
Normal file
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// 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
|
||||
Reference in New Issue
Block a user