1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

How can I use externally generated keys to encrypt and decrypt the data in iPhone?

Discussion in 'iPhone/iPad Programming' started by sspbond007, Oct 22, 2009.

  1. macrumors member

    #1
    I am working on an application, in which I need to encrypt and decrypt the data, with the keys generated by server. I viewed the sample code of Crypto Exercise. In that keys are automatically generated. How can I use externally generated keys in the code? Please help.
     
  2. macrumors 6502a

    #2
    I suppose you could do CGI programming in Objective-C, but if you're generating keys on the server then you now need to also encrypt their transit to your client. Depending on your needs, SSL should be strong enough for this.

    Perhaps you could tell us a little more about what you're trying to achieve so we can suggest a more appropriate scheme?
     
  3. macrumors member

    #3
    Thanks for reply.
    Actually we would save the key to the application before distributing iphone with application installed, application will be of no use without keys.
    As the admin will have the details of key.

    Key example generated at server:

    Public Key = Sun RSA public key, 1024 bits
    modulus: 124023351056468614901533017072321247442755935604055880454060007476890164438816752725874372294674015042581755934271759902049502111005389711791135502487008186937382304689292437368682143846990300465923690895265303828247563983908120112048903925521720479908415043670044545880379949571719973833044267594283578037267
    public exponent: 65537


    Private Key = Sun RSA private CRT key, 1024 bits
    modulus: 124023351056468614901533017072321247442755935604055880454060007476890164438816752725874372294674015042581755934271759902049502111005389711791135502487008186937382304689292437368682143846990300465923690895265303828247563983908120112048903925521720479908415043670044545880379949571719973833044267594283578037267
    public exponent: 65537
    private exponent: 114890545279601844443397943138649850519510438476857905583814289850458195725239236991936753534369197968325998817852095997884055154511927839122200092947323690104719921979672421871813387130149834682490921697661392281141856629258926789279733883254021403658980049918631649289303454629969269203849499935133081811361
    prime p: 12286772546456233633275173954900435004671958267370681732506625760473826004732448434908366238181160639947248110138614224358839989172329264022644016028973059
    prime q: 10094054446563315404837804379878204754449128284698017797970347835729750012713048675775291259987608136883717196181912050395526837190859701170692738982862513
    prime exponent p: 6258591756082036824688727469008975414818560245962364286987025462897260074705636908960525964404865734521857632493970713517114841365028423956969729879231695
    prime exponent q: 9594257283447854543206990103779134390712804966818879788076489729210638079129670691539045778219144697846415178976206805975832853842761073978436487735484865
    crt coefficient: 9270409267843644570790177803648197918946915567779960231096993691473748233824775338016370226367676538314640135208758120690734790651897457694493986394969199



    using this info we have to do all kind of cryptographic operation.

    Any suggestion.
     
  4. macrumors 6502a

    #4
    Wouldn't that mean that all instances of your app were doing their encryption/decryption with the same key pair? This would render such encryption moot, as anyone could simply extract the private key from memory and decrypt all data for all instances of your app.
     
  5. macrumors 603

    Cromulent

    #5
    Exactly.

    Your best bet is to have the application create a key pair on first launch then have it securely transmit the keys with a unique ID to the server so that it can associate each key with a specific instance of the application.
     
  6. macrumors member

    #6

    Sorry, the logic behind is somewhat different. The main problem is of how to create SecKeyRef with the keys? Or is there any other way to encrypt data with the key information?
     

Share This Page