示例#1
0
static CFDictionaryRef SecRSAPrivateKeyCopyAttributeDictionary(SecKeyRef key) {
	CFDictionaryRef dict = NULL;
	CFDataRef fullKeyBlob = NULL;

	/* PKCS1 encode the key pair. */
	fullKeyBlob = SecRSAPrivateKeyCopyPKCS1(key);
    require(fullKeyBlob, errOut);

	dict = SecKeyGeneratePrivateAttributeDictionary(key, kSecAttrKeyTypeRSA, fullKeyBlob);

errOut:
	CFReleaseSafe(fullKeyBlob);

	return dict;
}
static CFDictionaryRef SecECPrivateKeyCopyAttributeDictionary(SecKeyRef key) {
	CFDictionaryRef dict = NULL;
	CFAllocatorRef allocator = CFGetAllocator(key);

    ccec_full_ctx_t fullkey;
    fullkey.hdr = key->key;

	CFDataRef fullKeyBlob = NULL;

	/* Export the full ec key pair. */
	require(fullKeyBlob = SecECPPrivateKeyExport(allocator, fullkey), errOut);

	dict = SecKeyGeneratePrivateAttributeDictionary(key, kSecAttrKeyTypeEC, fullKeyBlob);

errOut:
	CFReleaseSafe(fullKeyBlob);

	return dict;
}