2010-12-31 7 views
1

안녕하세요, 사용자가 다양한 사운드를 구매할 수있는 앱 구매시 설정 중입니다. 일단 구입하면 그는 그 소리를 응용 프로그램에서 재생할 수 있습니다. 사운드 파일은 모두 Resources 폴더에 있으며, 구입 한 파일을 (plist로) 기록합니다. 아니요 IAP 파일을 마우스 오른쪽 버튼으로 클릭하고 해당 컨텐츠를 볼 수 있다면 리소스를 볼 수 있습니다. 따라서 실제로 아무 것도 구입하지 않고도 그 소리를들을 수 있습니다. 보호 번들 등이 있습니까?인앱 구매 리소스 보안

답변

1

해당 파일을 각각 암호화하고 구입할 때 해독하여 사용 가능하게 만들 수 있습니다.

.H :

#import <Foundation/Foundation.h> 

@interface NSData (DataCategory) 

- (NSData *)AES256EncryptWithKey:(NSString *)key; 
- (NSData *)AES256DecryptWithKey:(NSString *)key; 

@end 

하는 .m

#import "NSDataCategory.h" 
#import <CommonCrypto/CommonCryptor.h> 

@implementation NSData (DataCategory) 

- (NSData *)AES256EncryptWithKey:(NSString *)key { 
    // 'key' should be 32 bytes for AES256, will be null-padded otherwise 
    char keyPtr[kCCKeySizeAES256+1]; // room for terminator (unused) 
    bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding) 

    // fetch key data 
    [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]; 

    NSUInteger dataLength = [self length]; 

    //See the doc: For block ciphers, the output size will always be less than or 
    //equal to the input size plus the size of one block. 
    //That's why we need to add the size of one block here 
    size_t bufferSize = dataLength + kCCBlockSizeAES128; 
    void *buffer = malloc(bufferSize); 

    size_t numBytesEncrypted = 0; 
    CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding, 
              keyPtr, kCCKeySizeAES256, 
              NULL /* initialization vector (optional) */, 
              [self bytes], dataLength, /* input */ 
              buffer, bufferSize, /* output */ 
              &numBytesEncrypted); 
    if (cryptStatus == kCCSuccess) { 
     //the returned NSData takes ownership of the buffer and will free it on deallocation 
     return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted]; 
    } 

    free(buffer); //free the buffer; 
    return nil; 
} 

- (NSData *)AES256DecryptWithKey:(NSString *)key { 
    // 'key' should be 32 bytes for AES256, will be null-padded otherwise 
    char keyPtr[kCCKeySizeAES256+1]; // room for terminator (unused) 
    bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding) 

    // fetch key data 
    [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]; 

    NSUInteger dataLength = [self length]; 

    //See the doc: For block ciphers, the output size will always be less than or 
    //equal to the input size plus the size of one block. 
    //That's why we need to add the size of one block here 
    size_t bufferSize = dataLength + kCCBlockSizeAES128; 
    void *buffer = malloc(bufferSize); 

    size_t numBytesDecrypted = 0; 
    CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding, 
              keyPtr, kCCKeySizeAES256, 
              NULL /* initialization vector (optional) */, 
              [self bytes], dataLength, /* input */ 
              buffer, bufferSize, /* output */ 
              &numBytesDecrypted); 

    if (cryptStatus == kCCSuccess) { 
     //the returned NSData takes ownership of the buffer and will free it on deallocation 
     return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted]; 
    } 

    free(buffer); //free the buffer; 
    return nil; 
} 

@end 

코드 here에서 사용

다음은 간단 아이폰 OS에서 데이터를 암호화하도록 만드는 NSData 카테고리입니다.

+0

안녕하세요. 나는 파일을 암호화하고 해독하는 것이 좋은 생각이라고 생각하지만, 모든 사운드 파일을 암호화해야한다. 어느 것이 많은 시간과 노력이 필요합니다. 그러나 어쨌든 고마워요. 네 접근 방식이 좋아. – jAmi

-2

언제든지 사운드 파일의 일부 비트를 뒤집은 다음 앱에서 구입 한 뒤 뒤집을 수 있습니다. 변경되는 정도에 따라 파일 머리글을 손상 시키거나 수정할 때까지 오디오를 완전히 제거 할 수 있습니다.