I need to develop an mobile application (android|iphone) that download some mp3 music and store on userphone, but I need to ensure that the user doesnt distribute that mp3. I need a way to encrypt these files.
There´s something I can do?
Thanks
I need to develop an mobile application (android|iphone) that download some mp3 music and store on userphone, but I need to ensure that the user doesnt distribute that mp3. I need a way to encrypt these files.
There´s something I can do?
Thanks
You can use the CommonCrypto functions to encrypt/decrypt with AES and save the key in the keychain.
Here is some sample code:
#import <CommonCrypto/CommonCryptor.h>
+ (NSData *)doCipher:(NSData *)dataIn
iv:(NSData *)iv
key:(NSData *)symmetricKey
context:(CCOperation)encryptOrDecrypt
{
CCCryptorStatus ccStatus = kCCSuccess;
size_t cryptBytes = 0; // Number of bytes moved to buffer.
NSMutableData *dataOut = [NSMutableData dataWithLength:dataIn.length + kCCBlockSizeAES128];
ccStatus = CCCrypt( encryptOrDecrypt,
kCCAlgorithmAES128,
kCCOptionPKCS7Padding,
symmetricKey.bytes,
kCCKeySizeAES128,
iv.bytes,
dataIn.bytes,
dataIn.length,
dataOut.mutableBytes,
dataOut.length,
&cryptBytes);
if (ccStatus != kCCSuccess) {
NSLog(@"CCCrypt status: %d", ccStatus);
}
dataOut.length = cryptBytes;
return dataOut;
}
// Also add Security.framework to your project.
Note that this requires an iv (initialization vector) and a simmple password should not be used for a key. Good security requires more than a few crypto routines, it requires a good knowledge of cryptography and a through code review.