I Want to Create AES 128 using CFB Encryption with No Padding i.e.
Sample 1: secret data is \"HELLO WORLD\" key:10 A5 88 69 D7 4B E5 A3 74 CF 8
I have solved the by using this method
- (NSData *)AES128OperationWithEncriptionMode:(CCOperation)operation key:(NSData *)key iv:(NSData *)iv {
CCCryptorRef cryptor = NULL;
// 1. Create a cryptographic context.
CCCryptorStatus status = CCCryptorCreateWithMode(operation, kCCModeCFB, kCCAlgorithmAES, ccNoPadding, [iv bytes], [key bytes], [key length], NULL, 0, 0, kCCModeOptionCTR_BE, &cryptor);
NSAssert(status == kCCSuccess, @"Failed to create a cryptographic context.");
NSMutableData *retData = [NSMutableData new];
// 2. Encrypt or decrypt data.
NSMutableData *buffer = [NSMutableData data];
[buffer setLength:CCCryptorGetOutputLength(cryptor, [self length], true)]; // We'll reuse the buffer in -finish
size_t dataOutMoved;
status = CCCryptorUpdate(cryptor, self.bytes, self.length, buffer.mutableBytes, buffer.length, &dataOutMoved);
NSAssert(status == kCCSuccess, @"Failed to encrypt or decrypt data");
[retData appendData:[buffer subdataWithRange:NSMakeRange(0, dataOutMoved)]];
// 3. Finish the encrypt or decrypt operation.
status = CCCryptorFinal(cryptor, buffer.mutableBytes, buffer.length, &dataOutMoved);
NSAssert(status == kCCSuccess, @"Failed to finish the encrypt or decrypt operation");
[retData appendData:[buffer subdataWithRange:NSMakeRange(0, dataOutMoved)]];
CCCryptorRelease(cryptor);
return [retData copy];
}