我必須加密一個字符串,並在我的xCode項目的資源文件夾中有一個.CER(x.509)。我花了兩天想象如何,但沒有成功,所以現在是時候提問了。iPhone加密證書
蘋果的文檔很難閱讀...我發現這個框架可能是最難理解的......這些樣本都沒有幫助。
所以,我曾嘗試用下面的代碼:顯然這是行不通的:
我的Mac上我用OPENSSL但我發現沒有辦法重新OPENSSL SDK中的命令。所以,我很困惑...任何人?
NSData *cipherData = [NSData dataWithBytes:aCipherText length:iCipherLength];
NSLog(@"(%d) %@", status, cipherData);
這工作正常:
感謝很多:)
NSString *certPath = [[NSBundle mainBundle] pathForResource:@"Certificate" ofType:@"cer"];
SecCertificateRef myCertificate = nil;
NSData *certificateData = [[NSData alloc] initWithContentsOfFile:certPath];
myCertificate = SecCertificateCreateWithData(kCFAllocatorDefault, (CFDataRef)certificateData);
SecPolicyRef myPolicy = SecPolicyCreateBasicX509();
SecTrustRef myTrust;
SecTrustCreateWithCertificates(myCertificate, myPolicy, &myTrust);
SecKeyRef publicKey = SecTrustCopyPublicKey(myTrust);
uint8_t *pPlainText = (uint8_t*)"This is a test";
uint8_t aCipherText[1024];
size_t iCipherLength = 1024;
OSStatus status = SecKeyEncrypt(publicKey,
kSecPaddingPKCS1,
pPlainText,
strlen((char*)pPlainText) + 1,
aCipherText,
&iCipherLength);
}
你找到任何解決這個@Fabio – Dilshan 2012-12-31 21:11:44