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

Java Development

Reply
New Developer
anindyasen_82
Posts: 9
Registered: ‎09-11-2009
My Device: BlackBerry 9630

Problem in RSA encryption

Hi all,

 

I'm facing some problem in RSA encryption. Basically my application based on client server based and the server side is developed in C++ and there Crypto++ library has been used for crypto. I'm getting the servers public key in byte format. Now I've to initialize(create the object of RSAPublicKey) the public key in the device. So, my first question:

 

1. Is it possible to create an object of 2048 bit RSAPublicKey from the total byte data of the Public Key? If possible a sample code snip will of great help.

 

Secondly, I can also get the PublicExponent and the modulus of the public key. But while trying to encrypt the data using the RSAPublicKey generated by those PublicExponent and the modulus, the resulting encrypted data in not proper (I've the encrypted data to ckeck if the encryption is doing perfect).

 

Please help me with some sample code.

 

Thanks in advance.

 

 

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Problem in RSA encryption

1. You simply need to pass the modulus and the public exponent to the constructor of RSAPublicKey. I guess the public key you are using in C++ is encoded, most likely, in DER. So, you need to extract the modulus and public exponent from that container (e.g., ASN1InputByteArray might work).

 

2. Check whether the public exponent and modulus are identical on both sides. Check whether you are using some padding scheme in your C++ code.

Please use plain text.
New Developer
Shekhar_H
Posts: 122
Registered: ‎09-04-2008
My Device: Storm II Model 9550

Re: Problem in RSA encryption

Hello All,

 

I am also facing the same problem, i follow the solution suggested by Klyubin, but i got ASN1EncodingException.

 

Can someone tell cause of this, and any solution this?

 

-Shekhar.

 

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Problem in RSA encryption

I suggest you first find out in what encoding the key is. Trying random things and hoping they'll work is not a good approach to security.

Please use plain text.
Contributor
mariomunera89
Posts: 15
Registered: ‎10-10-2012
My Device: Blackberry 10 Dev Alpha

Re: Problem in RSA encryption

Hi. I'm new working with Blackberry10 and I have to encrypt a password with RSA. I've been searching in blackberry developers site and I've found the hursa.h security API. I have some experience working with Blackberry in Java and I know that in Java the first thing to do once you got the Module and the public exponent is to create the RSA publick Key object, e.g. RSAPublicKey publicKey = new RSAPublicKey(new RSACryptoSystem(2048), ebytes, mbytes); I'm trying to perform this exact task in the new BB10 platform with C++ and I've not been successful.
I've seen several methods in the page but none of them is properly documented, like this one hu_RSAKeySet(), which I think I should be using. I've tried to use it, but I know for sure that I'm missing something, I dont know If I should create an object of this hursa class or something like that. Right now I'm just including hursa into my class and trying to implement the method and the message I get is "undefined reference to `hu_RSAKeySet'"

 

Any help will be appreciated. Any at all. Like I said I'm not a Guru in RSA encrypting process but I've perfomed this ecrypting in old Blackberry java paltform and it wasn't this hard.

 

Thanks to all and best regards.

 

PD: sorry for posting in this thread but I'm kind of desperate right now for finding some info or examples about it. 

Please use plain text.