English 中文(简体)
SecKeyGeneratePair Return errSecUnimplement
原标题:SecKeyGeneratePair returns errSecUnimplemented

试图将RSA加密算法应用到我的SOS,但当我试图产生公私营钥匙时,该功能使我回到错误中。 我现在使用5.1SDK,以5.1为目标。

我能否不利用这一职能,或者我是否在试图创造奶牛时搞错?

这里是我关于关键一代的法典:

SecKeyRef publicKey, privateKey;
CFDictionaryRef parameters;
const void* keys[] = {kSecAttrKeyType, kSecAttrKeyTypeRSA};
int keySize = 1024;
const void *values[] = {kSecAttrKeySizeInBits, &keySize};

parameters = CFDictionaryCreate(kCFAllocatorDefault, keys, values, 2, NULL, NULL);
OSStatus ret = SecKeyGeneratePair(parameters, &publicKey, &privateKey);
if ( ret == errSecSuccess )
{
    NSLog(@"Key success!");
}
else 
{
    NSLog(@"Key Failure! %li", ret);
}
最佳回答

我对它做了修订,以完成你们的解决办法。 (1) 你们需要使用CFNumberRef,而不是计算数值的点子。 (2) 价值必须是价值,关键是关键因素——你们正在把每个“钥匙”和“价值”的关键和价值混为一谈。

SInt32 iKeySize = 1024;
CFNumberRef keySize = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &iKeySize);
const void* values[] = { kSecAttrKeyTypeRSA, keySize };
const void* keys[] = { kSecAttrKeyType, kSecAttrKeySizeInBits };
CFDictionaryRef parameters = CFDictionaryCreate(kCFAllocatorDefault, keys, values, 2, NULL, NULL);

SecKeyRef publicKey, privateKey;
OSStatus ret = SecKeyGeneratePair(parameters, &publicKey, &privateKey);
if ( ret == errSecSuccess )
    NSLog(@"Key success!");
else 
    NSLog(@"Key Failure! %li", ret);
问题回答

::

const void* keys[] = {kSecAttrKeyType, kSecAttrKeySizeInBits};
int keySize = 1024;
const void *values[] = {kSecAttrKeyTypeRSA, &keySize};

即,关键应是字典的关键和价值,目前你在钥匙上(关键、价值)是一对,在价值上是一对。

Using kCFAllocatorSystemDefault instead of kCFAllocatorDefault return errSecSuccess.





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签