Не получен ключ в кодировке base64 из пары ключей RSA цель C - PullRequest
0 голосов
/ 18 апреля 2020

Получение ключей, как показано ниже:

publicKeyKey:   
<SecKeyRef algorithm id: 1, key type: RSAPublicKey, version: 4, block size: 2048 bits, exponent: {hex: 10001, decimal: 65537}, modulus: A424EF4D13BEE452C06DD738B207398D0CEE126CB9CE2B8B296B770B6DC3B5FAD2DD6DABBE587742978514ABA300EEF3CBBA55F7955241FFB4ED50305CCA05330D54F40965520EA65F4E2E8367CC0C163E1753720706D6F35D207A7456634AA95F3CD81419AA6A89535F01176D48D24597EBF74F1BE0A25A6A3F2B0F75D80A66F4E179B3D9E91988C0559565382A7B633A94360081FF81351A42C4FFE75BD5E477371E8EC638E1F3BD79B732BB24D6E8D77ECFB822F24D372942A337403AB184110143AD919F758F290502B894325E1DE37D4CD98B67816CFED248860E5D0B196D832FD5AF940914FC386FB6E6777C2ED9CCF1115CC3063EA522283C5399AB4B, addr: 0x6000031a46c0>

privateKey: <SecKeyRef algorithm id: 1, key type: RSAPrivateKey, version: 4, block size: 2048 bits, addr: 0x6000031a4740>

Мне нужны ключи в следующем формате:

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4BnVuztkRchGqYEmZCEJydC4ywp0pCepgrZeyTSAj5HDdbjwxpYe1HT70uBPZISnLu5rCHfHL+f16/YUG64KMOAKMlpUGsBfrBZttQ9m1Ky7I6brlyBBU3Eqya1/DK0qNiuUucx8Bw+T6dxH5HDA1FBGWkkl5DfcR1QmYYobCrvtupWfycs/DMG8wHwEdmC3zUHina8dqv/6p8uX22B8GZq1c31btmr2eIJAxmNFN4B9kObMnCL2pipQxfwc4rkxr0rA39ePrQbRAu6Uvh8EZMV2kDE3iASQH1h2ql0pqjyP8WCHt0XCScGuncG0TS5ygqcrylz6QCkB0N1r0nji5wIDAQAB
-----END PUBLIC KEY-----

SAME FOR PRIVATE KEY AS WELL WITH : 
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----

Это код, который я использую для генерации пары ключей RSA, с этим кодом мой publi c и закрытый ключ приходят в вышеуказанном формате.

- (void)generateKeyPair:(NSUInteger)keySize {
    OSStatus sanityCheck = noErr;
    publicKey = NULL;
    privateKey = NULL;
  // 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:(__bridge id)kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType];
    [keyPairAttr setObject:[NSNumber numberWithUnsignedInteger:keySize] forKey:(__bridge id)kSecAttrKeySizeInBits];

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

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

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

    // SecKeyGeneratePair returns the SecKeyRefs just for educational purposes.
    sanityCheck = SecKeyGeneratePair((__bridge CFDictionaryRef)keyPairAttr, &publicKey, &privateKey);
//  LOGGING_FACILITY( sanityCheck == noErr && publicKey != NULL && privateKey != NULL, @"Something really bad went wrong with generating the key pair." );
    if(sanityCheck == noErr  && publicKey != NULL && privateKey != NULL)
    {
        NSLog(@"Successful");
    }
 }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...