Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
BlackBerry Development Advisor (Retired)
robbieDubya
Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: How to create RAS Keys?

Hi,

 

Yeah - AES and RSA aren't related. You'd still need to decide how to be using the same AES key at both ends.

 

Storing the key is a chicken and an egg problem. Using the OpenSSL encoding of the key is a good way to store it... No other application should be able to read it if stored in your application's sand box. Also depends on your usage. Is it per user? Or is it built into your application?

 

How much data are you talking about? RSA isn't performance effective for encrypting anything above the modulus size. This is where AES (or another block/stream cipher) would come into play.

 

Hope this helps!

--
Rob is no longer associated with BlackBerry.
Please use plain text.
Developer
smiley
Posts: 1,448
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: How to create RAS Keys?

[ Edited ]

I'm testing your code and it outputs the keys to the console and then it crashes with this error

 

edit: ignore.  Rookie error. Sorry

Please use plain text.
Developer
smiley
Posts: 1,448
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: How to create RAS Keys?

I'm now able to generate the public and private keys.

 

I'm saving the n, d, e params to a structure for later use and then when I want to encypt i use this step

 

        //  to encrypt use the public key


        if (hu_RSAKeySet(rsaParams, public_key->i_eLen, (const unsigned char *)&public_key->e, public_key->i_nLen,  (const unsigned char *)&public_key->n,  dLen, NULL,
                 pLen, NULL, qLen, NULL,  dModPLen, NULL,
                 dModQLen, NULL, qInvLen, NULL, NULL, &publicKey, globalContext.ctx())  == SB_SUCCESS)

      // to decrypt use the private key

 

                if (hu_RSAKeySet(rsaParams, _Prefs->KeyParam.eLen, (const unsigned char *)&_Prefs->KeyParam.e, _Prefs->KeyParam.nLen,  (const unsigned char *)&_Prefs->KeyParam.n,  _Prefs->KeyParam.dLen, (const unsigned char *)&_Prefs->KeyParam.d,
                         pLen, NULL, qLen, NULL,  dModPLen, NULL,
                         dModQLen, NULL, qInvLen, NULL,  &privateKey, NULL, globalContext.ctx())  == SB_SUCCESS)

I'm able to encrypt and decrypt in my test code if I encrypt the data and then immediately decrypt the data.

 

The problem is when I saved the encrypted data and then try to decrypt it later it does not work.

 

I'm using the doc from here https://developer.blackberry.com/native/reference/core/com.qnx.doc.crypto.lib_ref/topic/hu_rsakeyset...

 

 

Please use plain text.
BlackBerry Development Advisor (Retired)
robbieDubya
Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: How to create RAS Keys?

Hi,

 

Can you share more of the code relating to the storing / loading?

 

As you say - the encrypting/decrypting works when things aren't getting stored and loaded later...

 

Thanks.

 

--
Rob is no longer associated with BlackBerry.
Please use plain text.