How to find out the modulus and exponent of RSA Public Key on iPhone/Objective C

前端 未结 4 753
感情败类
感情败类 2020-12-01 11:43

Is there a possible way to find out the modulus and exponent of the Public Key, created with SecKeyGeneratePair (the Security Framework in general)?

4条回答
  •  眼角桃花
    2020-12-01 12:20

    I removed that extra byte at the beginning, now it works fine. In my case it was always extracting 129 bytes modulus.

    - (NSData *)getPublicKeyModFromKeyData:(NSData*)pk
    {
    if (pk == NULL) return NULL;
    
    int iterator = 0;
    
    iterator++; // TYPE - bit stream - mod + exp
    [self derEncodingGetSizeFrom:pk at:&iterator]; // Total size
    
    iterator++; // TYPE - bit stream mod
    int mod_size = [self derEncodingGetSizeFrom:pk at:&iterator];
    
    // return [pk subdataWithRange:NSMakeRange(iterator, mod_size)];
    NSData* subData=[pk subdataWithRange:NSMakeRange(iterator, mod_size)];
    return  [subData subdataWithRange:NSMakeRange(1, subData.length-1)];
    
    }
    

提交回复
热议问题