2012-07-19 15 views
10

क्या आईओएस में ईसीसी का उपयोग करने के लिए कोई उदाहरण है?आईओएस में ईसीसी का उपयोग कैसे करें

मैंने देखा कि ऐप्पल डेवलपर दस्तावेज़ों में केएसईएएएटीएकेटीपीईपीईसी, लेकिन मैं इसे सामान्य कुंजी जोड़ी में उपयोग नहीं कर सकता।

कोड नीचे दिए उदाहरण से संशोधित किया गया है CryptoExercise

// Container dictionaries. 
NSMutableDictionary * privateKeyAttr = [[NSMutableDictionary alloc] init]; 
NSMutableDictionary * publicKeyAttr = [[NSMutableDictionary alloc] init]; 
NSMutableDictionary * keyPairAttr = [[NSMutableDictionary alloc] init]; 

// Set top level dictionary for the keypair. 
[keyPairAttr setObject:(id)kSecAttrKeyTypeEC forKey:(id)kSecAttrKeyType]; 
[keyPairAttr setObject:[NSNumber numberWithUnsignedInteger:keySize] forKey:(id)kSecAttrKeySizeInBits]; 

// Set the private key dictionary. 
[privateKeyAttr setObject:[NSNumber numberWithBool:YES] forKey:(id)kSecAttrIsPermanent]; 
[privateKeyAttr setObject:privateTag forKey:(id)kSecAttrApplicationTag]; 
// See SecKey.h to set other flag values. 

// Set the public key dictionary. 
[publicKeyAttr setObject:[NSNumber numberWithBool:YES] forKey:(id)kSecAttrIsPermanent]; 
[publicKeyAttr setObject:publicTag forKey:(id)kSecAttrApplicationTag]; 
// See SecKey.h to set other flag values. 

// Set attributes to top level dictionary. 
[keyPairAttr setObject:privateKeyAttr forKey:(id)kSecPrivateKeyAttrs]; 
[keyPairAttr setObject:publicKeyAttr forKey:(id)kSecPublicKeyAttrs]; 

// SecKeyGeneratePair returns the SecKeyRefs just for educational purposes. 
sanityCheck = SecKeyGeneratePair((CFDictionaryRef)keyPairAttr, &publicKeyRef, &privateKeyRef); 
LOGGING_FACILITY(sanityCheck == noErr && publicKeyRef != NULL && privateKeyRef != NULL, @"Something really bad went wrong with generating the key pair."); 

sanityCheck हमेशा -50 जो 'errSecParam' का अर्थ है लौटने।

मुझे वास्तव में यह नहीं पता कि इसका उपयोग कैसे किया जाए, इसे पढ़ने के लिए धन्यवाद।

+1

कुंजीजुट = 256 जब कोड पारित किया गया, लेकिन दूसरी समस्या यह है कि जब मैं SecKeyRawSign का उपयोग करता हूं, तो यह -1 देता है, और मुझे -1 रिटर्न वैल्यू के लिए विवरण नहीं मिल रहा है, क्या कोई इसे पूरा करता है मुसीबत? – Cylon

+0

क्या आपको इस समस्या का समाधान मिल गया है? – Gunhan

उत्तर

1
NSDictionary *parameters = @{ 
          (__bridge id)kSecAttrKeyType: (__bridge id)kSecAttrKeyTypeEC, 
          (__bridge id)kSecAttrKeySizeInBits: @256, 
          (__bridge id)kSecPrivateKeyAttrs: @{ 
            (__bridge id)kSecAttrIsPermanent: @YES, 
            (__bridge id)kSecAttrApplicationTag: [@"my.key.tag" dataUsingEncoding:NSUTF8StringEncoding], 
            }, 
          (__bridge id)kSecPublicKeyAttrs: @{ 
            (__bridge id)kSecAttrIsPermanent: @YES, 
            (__bridge id)kSecAttrApplicationTag: [@"my.key.pubtag" dataUsingEncoding:NSUTF8StringEncoding], 
            } 
          }; 

SecKeyRef publicKey, privateKey; 
OSStatus status = SecKeyGeneratePair((__bridge CFDictionaryRef)parameters, &publicKey, &privateKey); 

यह काम करता है, अपने कुंजी आकार पैरामीटर को दोबारा जांचें।

बस एक नोट, वर्तमान में ईसी कुंजी का उपयोग डेटा पर हस्ताक्षर/सत्यापन के लिए किया जा सकता है। एन्क्रिप्शन/डिक्रिप्शन रिटर्न errSecUnimplemented = -4.

+0

कृपया [बग्रेपोर्ट] (http://bugreport.apple.com)। आईओएस के लिए क्रिप्टोग्राफिक क्षमताओं को उपलब्ध कराने पर ऐप्पल पीछे है। – zaph

संबंधित मुद्दे