Skip to content

karstenBriksoft/CSSMPublicKeyDecrypt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSSMPublicKeyDecrypt

Implementation of Public-Key Decrypt using CSSM in Security.framework

Usage

NSData* pemData = [NSData dataWithContentsOfFile:@"keyFile.pem"];
SecExternalFormat format = kSecFormatOpenSSL;
SecExternalItemType itemType = kSecItemTypePrivateKey;
SecKeyImportExportFlags importExportFlags = 0;
SecItemImportExportKeyParameters parameters = {};
NSArray* items = @[];

OSStatus importWorked = SecItemImport((CFDataRef)pemData, NULL, &format, &itemType, importExportFlags, &parameters, NULL, (CFArrayRef*)&items);
if (importWorked == noErr)
{
	for (id idKey in items)
	{
		SecKeyRef key = (SecKeyRef)idKey;
		NSError* error = nil;
		
		NSData* decryptedData = [CSSMPubKeyDecrypt decryptData:encryptedData usingPublicKey:key error:&error];
		if (!decryptedData)
		{
			NSLog(@"error decrypting data: %@", error);
		}
	}
	CFRelease((CFArrayRef)items);
}

About

Implementation of Public-Key Decrypt using CSSM in Security.framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published