I have many pieces of code that encrypt data using AES128 (if you provide your working implementation, I will be very grateful) For example, this:
- (NSData*)AES128EncryptWithKey:(NSString*)key {
char keyPtr[kCCKeySizeAES128 + 1];
bzero(keyPtr, sizeof(keyPtr));
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
NSUInteger dataLength = [self length];
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void* buffer = malloc(bufferSize);
size_t numBytesEncrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, kCCOptionECBMode + kCCOptionPKCS7Padding,
keyPtr, kCCKeySizeAES128,
NULL ,
[self bytes], dataLength,
buffer, bufferSize,
&numBytesEncrypted);
if (cryptStatus == kCCSuccess)
{
return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
}
free(buffer);
return nil;
}
After that, the data is encoded by base64, using the online tool I save it in data.bin
What I want to do is decrypt this data using OpenSSl. But when I call
openssl enc -aes-128-ecb -in data.bin -out out.bin -d -pass pass:0123456789123456
He told me a bad magic number
If i use
openssl enc -aes-128-ecb -in data.bin -out out.bin -d -pass pass:0123456789123456 -nosalt
He told me bad to decrypt
Please, help.
source
share