1.1 --- a/MYKey-iPhone.m Tue Apr 07 10:56:58 2009 -0700
1.2 +++ b/MYKey-iPhone.m Thu Apr 09 22:46:48 2009 -0700
1.3 @@ -109,6 +109,35 @@
1.4 }
1.5
1.6
1.7 +
1.8 +
1.9 +/** Asymmetric encryption/decryption; used by MYPublicKey and MYPrivateKey. */
1.10 +- (NSData*) _crypt: (NSData*)data operation: (BOOL)operation {
1.11 + CAssert(data);
1.12 + size_t dataLength = data.length;
1.13 + SecKeyRef key = self.keyRef;
1.14 + size_t outputLength = MAX(dataLength, SecKeyGetBlockSize(key));
1.15 + void *outputBuf = malloc(outputLength);
1.16 + if (!outputBuf) return nil;
1.17 + OSStatus err;
1.18 + if (operation)
1.19 + err = SecKeyEncrypt(key, kSecPaddingNone,//PKCS1,
1.20 + data.bytes, dataLength,
1.21 + outputBuf, &outputLength);
1.22 + else
1.23 + err = SecKeyDecrypt(key, kSecPaddingNone,//PKCS1,
1.24 + data.bytes, dataLength,
1.25 + outputBuf, &outputLength);
1.26 + if (err) {
1.27 + free(outputBuf);
1.28 + Warn(@"%scrypting failed (%i)", (operation ?"En" :"De"), err);
1.29 + // Note: One of the errors I've seen is -9809, which is errSSLCrypto (SecureTransport.h)
1.30 + return nil;
1.31 + } else
1.32 + return [NSData dataWithBytesNoCopy: outputBuf length: outputLength freeWhenDone: YES];
1.33 +}
1.34 +
1.35 +
1.36 @end
1.37
1.38