//
//  CypherUtil.m
//  JasonDevelop
//
//  Created by Jason Lee on 8/6/14.
//  Copyright (c) 2014 JasonDevelop All rights reserved.
//
#import "NSData+AESCrypt.h"
#import "CypherUtil.h"

@implementation CypherUtil

+ (NSString *)AES256Encrypt:(NSString *)plainText WithKey:(NSString *)key
{
	NSData *plainData = [plainText dataUsingEncoding:NSUTF8StringEncoding];
	NSData *encryptedData = [plainData AES256EncryptWithKey:key];
	
	NSString *encryptedString = [encryptedData hexEncode];
	
	return encryptedString;
}

+ (NSString *)AES256Decrypt:(NSString *)enctyptText WithKey:(NSString *)key
{
	NSData *encryptedData = [NSData decodeHexString:enctyptText];
    
	NSData *plainData = [encryptedData AES256DecryptWithKey:key];
	
	NSString *plainString = [[NSString alloc] initWithData:plainData encoding:NSUTF8StringEncoding];
	
	return plainString;
}

+ (NSString *)AES128Encrypt:(NSString *)plainText WithKey:(NSString *)key
{
	NSData *plainData = [plainText dataUsingEncoding:NSUTF8StringEncoding];
	NSData *encryptedData = [plainData AES128EncryptWithKey:key];
	
	//NSString *encryptedString = [encryptedData base64Encoding];
	NSString *encryptedString = [encryptedData hexEncode];
	
	return encryptedString;
}

+ (NSString *)AES128Decrypt:(NSString *)enctyptText WithKey:(NSString *)key
{
	NSData *encryptedData = [NSData decodeHexString:enctyptText];
	
	NSData *plainData = [encryptedData AES128DecryptWithKey:key];
	
	NSString *plainString = [[NSString alloc] initWithData:plainData encoding:NSUTF8StringEncoding];
	
	return plainString;
}

@end
