Base64'te bir RSa publicKey değeri var, nasıl Anahtar Zincirine ekleme yapmadan SecKeyRef nesnesine nasıl dönüşebilirim X509 biçiminde olmayan bir RSA Raw değerini bir RSA Raw değeri ekleyebilir miyim? ?? peşinHam RSA Anahtar değeri Encrypt için SecKeyRef Nesnesine Dönüştürme
8
A
cevap
2
Aşağıdaki kod SecKeyWrapper.m de, Apple'ın CryptoExercise örnekten gelir içinde
teşekkürler. "PublicKey" NSData nesnesinin, kodlanmış base-64 değil, ikili DER kodlu ASN.1 nesnesi olduğunu varsayar. Bu yüzden bir 64 taban kod çözücüsünü almanız ve önce onu uygulamanız gerekir. Apple Developer Forumlarında this post'u da okumak isteyebilirsiniz.
- (SecKeyRef)addPeerPublicKey:(NSString *)peerName keyBits:(NSData *)publicKey {
OSStatus sanityCheck = noErr;
SecKeyRef peerKeyRef = NULL;
CFTypeRef persistPeer = NULL;
LOGGING_FACILITY(peerName != nil, @"Peer name parameter is nil.");
LOGGING_FACILITY(publicKey != nil, @"Public key parameter is nil.");
NSData * peerTag = [[NSData alloc] initWithBytes:(const void *)[peerName UTF8String] length:[peerName length]];
NSMutableDictionary * peerPublicKeyAttr = [[NSMutableDictionary alloc] init];
[peerPublicKeyAttr setObject:(id)kSecClassKey forKey:(id)kSecClass];
[peerPublicKeyAttr setObject:(id)kSecAttrKeyTypeRSA forKey:(id)kSecAttrKeyType];
[peerPublicKeyAttr setObject:peerTag forKey:(id)kSecAttrApplicationTag];
[peerPublicKeyAttr setObject:publicKey forKey:(id)kSecValueData];
[peerPublicKeyAttr setObject:[NSNumber numberWithBool:YES] forKey:(id)kSecReturnPersistentRef];
sanityCheck = SecItemAdd((CFDictionaryRef) peerPublicKeyAttr, (CFTypeRef *)&persistPeer);
// The nice thing about persistent references is that you can write their value out to disk and
// then use them later. I don't do that here but it certainly can make sense for other situations
// where you don't want to have to keep building up dictionaries of attributes to get a reference.
//
// Also take a look at SecKeyWrapper's methods (CFTypeRef)getPersistentKeyRefWithKeyRef:(SecKeyRef)key
// & (SecKeyRef)getKeyRefWithPersistentKeyRef:(CFTypeRef)persistentRef.
LOGGING_FACILITY1(sanityCheck == noErr || sanityCheck == errSecDuplicateItem, @"Problem adding the peer public key to the keychain, OSStatus == %d.", sanityCheck);
if (persistPeer) {
peerKeyRef = [self getKeyRefWithPersistentKeyRef:persistPeer];
} else {
[peerPublicKeyAttr removeObjectForKey:(id)kSecValueData];
[peerPublicKeyAttr setObject:[NSNumber numberWithBool:YES] forKey:(id)kSecReturnRef];
// Let's retry a different way.
sanityCheck = SecItemCopyMatching((CFDictionaryRef) peerPublicKeyAttr, (CFTypeRef *)&peerKeyRef);
}
LOGGING_FACILITY1(sanityCheck == noErr && peerKeyRef != NULL, @"Problem acquiring reference to the public key, OSStatus == %d.", sanityCheck);
[peerTag release];
[peerPublicKeyAttr release];
if (persistPeer) CFRelease(persistPeer);
return peerKeyRef;
}
1
durumda birisi bu soruya rastlar ve Kakao cevap arıyor:
NSData *privateKeyPEMData = [privateKeyPEM dataUsingEncoding:NSUTF8StringEncoding];
CFArrayRef imported = NULL;
SecKeychainRef importedKeychain = NULL;
OSStatus err = 0;
SecExternalFormat format = kSecFormatOpenSSL;
SecKeyRef privateKey = NULL;
[privateKeyString dataUsingEncoding:NSUTF8StringEncoding];
err = SecItemImport((__bridge CFDataRef)(privateKeyPEMData), (CFStringRef)@"pem", &format, NULL, kNilOptions, kNilOptions, importedKeychain, &imported);
NSLog(@"%@ ERROR: %@", self.class, [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil]);
assert(err == errSecSuccess);
assert(CFArrayGetCount(imported) == 1);
privateKey = (SecKeyRef)CFArrayGetValueAtIndex(imported, 0);
İlgili konular
- 1. Ham HTTP İsteğini HTTPWebRequest Nesnesine Dönüştürme
- 2. Yesod'un Persistent'inde ham anahtar değeri nasıl alınır?
- 3. JObject dinamik nesnesine dönüştürme
- 4. JSON nesnesine dönüştürme Nesne
- 5. RSA Şifreleme-Şifre çözme, iPhone
- 6. RSA ortak anahtarına ham modül ve üssün dönüştürülmesi (.pem biçimi)
- 7. Bir NSMutableData nesnesine ham bayt nasıl yazılır?
- 8. Jquery nesnesine bir şey dönüştürme
- 9. Özel anahtar RSA özel anahtarına nasıl dönüştürülür?
- 10. Java'da RSA anahtar nesnesini XML'ye dışa aktarma
- 11. Java RSA anahtar boyutunu anlamaya çalışmak
- 12. Lets Encrypt Hatası "urn: acme: error: yetkisiz"
- 13. RSA
- 14. Dize, Tarih olmadan Zaman nesnesine dönüştürme
- 15. XStream kullanarak nesne XML nesnesine dönüştürme nasıl
- 16. r veri çerçevesini h2o nesnesine dönüştürme
- 17. utc saat dizgesini datetime nesnesine dönüştürme
- 18. JSON dizesini Scala'daki bir JSON nesnesine dönüştürme
- 19. Ortak anahtarı (iPhone'da seckeyref olarak oluşturulmuş) sunucuya gönder (Java)
- 20. Dinamik liste değerlerini liste nesnesine dönüştürme
- 21. XmlDocument nesnesini bir XmlNode nesnesine dönüştürme - C#?
- 22. Dizeyi UTC ofsetiyle bir datetime nesnesine dönüştürme
- 23. Eşleme yaparken değeri dönüştürme
- 24. CookieError: Geçersiz anahtar değeri
- 25. RSA ortak anahtarını RSA DER
- 26. anahtar değeri 'anahtar' ile değiştirilirken() twer
- 27. Geçiş değeri, anahtar olarak sözlükte anahtar olarak
- 28. Json :: Değeri std :: dizesine dönüştürme?
- 29. RSA: Genişletilmiş Öklid Algoritması ile özel anahtar hesaplaması
- 30. RSA şifrelemek/şifresini çözmek
@bs bu bağlantıyı yardımcı olacağını umuyoruz u http://blog.wingsofhermes.org/?p = 75 – 012346