RSA encrypt in C++ Blackberry10

Hello. I'm new with Blackberry10 and I need to encrypt a password with the RSA. I searched in the blackberry developers website and I found the hursa.h API security. I have experience working with Blackberry in Java and I know that in Java, the first thing to do once got you the Module and the public exponent is to create the object of RSA publick key, e.g. RSAPublicKey publicKey = new RSAPublicKey (new RSACryptoSystem (2048), ebytes, Mo); I am trying to perform this exact task in the new platform BB10 with C++ and I failed.
I've seen several methods in the page, but none of them are complete, like a hu_RSAKeySet(), I think I should use. I tried to use it, but I know I'm missing something, I don't know if I should create an object of this class of hursa or something like that. For now I'm just including hursa in my class and try to implement the method and the message I get is "undefined reference to"hu_RSAKeySet '"

Any help will be appreciated. Not at all. As I said I am not a guru in the RSA encryption of the process, but I made this ecrypting in the old Blackberry java platform and it wasn't that hard.

Thank you all and consider better.

Solved. After doing some research and getting to know better with BB10 and RSA encoding, I've finally came out with the solution to successfully encrypt a plain text with RSA and Base64 in C/C++ for BB10 or any other platform. Please take into consideration that I have the module and the public object rsa exponent since I'm working with services.

Code:

QByteArray answer;

    RSA* rsa = RSA_new();

    BIGNUM *modulus = BN_new();
    BIGNUM *exponent = BN_new();
    constchar*modulusString = rsaObj->getM();//My Modulus
    constchar*exponentString = rsaObj->getE();//My exponent

    BN_hex2bn(&modulus, modulusString);
    BN_hex2bn(&exponent, exponentString);

    rsa->n = BN_new();
    BN_copy(rsa->n, modulus);
    rsa->e = BN_new();
    BN_copy(rsa->e, exponent);

    int maxSize = RSA_size(rsa);
    qDebug()<<"maxSize:"<< maxSize;

    constchar*inn ="1234";
    unsignedchar*encrypted =(unsignedchar*) malloc(maxSize);
    int bufferSize = RSA_public_encrypt(strlen(inn),(unsignedchar*) inn,
            encrypted, rsa, RSA_PKCS1_PADDING);

    if(bufferSize ==-1){
        RSA_free(rsa);
        qDebug()<<"Error";
    }

    QByteArray enc =QByteArray::fromRawData((constchar*) encrypted,256);
    answer = enc.toBase64();

    return answer;

Thank you and I hope this helps for new developers BB10

Tags: BlackBerry Developers

Similar Questions

  • RSA encryption problem

    Hi guys,.

    I use code below for RSA encryption. Always out.size () gives the value 0. but it's not throw an exception. Where is the problem? Please help me.

    module of the private channel = "2CmNWUxYnaX5A5musNu8D6mOsYlnguGV1m + CGp4pKHMM2KV0izVOUjDHnhNbWUOLQfSMId5bXkmIqYPTKZ2KqZ16GNt65ygUjJxfZlFmOMGicTADkaHciPP8ZIxQmBdtta0pqeRP5AD + FG y144BzfNWCAXkPlo7Vwph2dMvb8E plus";
    Exhibitor private string = "Collaboration."
    Private String data = "Welcome to Cryptography."

    Private byte [] RSAencrypt (byte [] data) throws IOException, NoSuchAlgorithmException, CryptoException
    {

    Cryptosystem of RSACryptoSystem = new RSACryptoSystem (1024);

    Expo of Byte [] = null;
    Byte [] modul = null;

    Try
    {
    Expo = Base64InputStream.decode (Exhibitor, 0, exponent.length ());
    Modul = Base64InputStream.encode (module a, 0, modulus.length ());
    catch (IOException ioe)
    {
    }

    If (expo == null | modul == null)
    Returns a null value.

    RSAPublicKey publicKey = new RSAPublicKey (cryptosystem, expo, modul);

    NoCopyByteArrayOutputStream out = new NoCopyByteArrayOutputStream();
    Engine RSAEncryptorEngine = new RSAEncryptorEngine (publicKey);
    PKCS1FormatterEngine fengine = new PKCS1FormatterEngine (engine);
     
    CryptoStream BlockEncryptor = new BlockEncryptor (fengine, out);

    cryptoStream.write (data, 0, data.length);

    int finalLength = out.size ();
    Byte [] cipherText = new ubyte [finalLength];

    System.arraycopy (encrypted text, out.getByteArray (), 0, 0, finalLength);

    String txt = new String (cipherText);

    } catch (Exception ex) {}
    System.out.println ("EncryptString:" + ex.toString ());
    }

    Thanks in advance,

    I found the solution. Need to close the two cryptoStream and out as below

    cryptoStream.write (data, 0, data.length);

    cryptoStream.close ();

    out. Close();

    Thank you

  • RSA encryption and

    Hello

    I'm trying to implement encryption RSA BB10 and. Currently I have a poor visibility of the BB implementations of them. This link provides an example of one-way encryption (which I am not after) and this discussion provides an example that uses the openssl library.

    I prefer to use the BB10 or is it better to use openssl? There are some examples that I can follow? Or please tell me the proper documentation.

    Thank you

    It is the starting point,

    http://developer.BlackBerry.com/native/reference/BB10/com.QNX.doc.crypto/topic/c_sb_overview.html

    There is an example of code here...

    http://supportforums.BlackBerry.com/T5/native-development/AES-encryption-decryption-is-not-working-p...

    Note: Looking at your previous posts it seems you just ask your question and then leave it at that.  If you want to encourage others to help in your problems then please get used to using the "as - thumbs up" next to the post office and closing your job offers by accepting one of the answers as the solution.

  • RSA encryption using the .cer file

    Hi all

    I need to encrypt my data using RSA with a public key stored in my file system. (assets)

    as with iOS and android, we .cer file, what file format do I need to store in my file system, which I will extract the public key?

    and any snippet of code that I can refer to, to get the public key of the certificate for encryption?

    Help, please!

    Kind regards.

    That's what I did to read the file:

    QFile file (CERTIFICATE_PATH);
    If (file. Exists())
    {
    leader. Open (QIODevice::ReadOnly);
    QByteArray certificateDataBytes = file.readAll ();

    int length = certificateDataBytes.size ();
    X 509 * certificate;

    const unsigned char * data = (unsigned char *) certificateDataBytes.data ();

    length is the length of the certificateDataBytes in terms of bytes.
    certificate = d2i_X509 (NULL, & data, length);

    _publicKey = X509_get_pubkey (certificate);

    RSA * rsa;
    RSA = EVP_PKEY_get1_RSA (_publicKey);

    int maxSize = RSA_size (rsa);

    char * inputPainText = convertToUStr (plainText);
    unsigned char * encrypted = (unsigned char *) malloc (maxSize);
    int bufferSize = RSA_public_encrypt (strlen (inputPainText), (unsigned char *) inputPainText, encrypted, rsa, RSA_PKCS1_PADDING);

    }

    Thank you all

  • Problem with RSA encryption

    I have a problem when you try to encrypt an array of bytes using RSA. I use the example given in the http://supportforums.blackberry.com/t5/Java-Development/Use-Advanced-Encryption/ta-p/445085.

    Unfortunately, this code does not work.

                            byte[] content = secureNotes.toString().getBytes();
    
                System.out.println("Content: "+new String(content));
    
                System.out.println("1");
    //          NoCopyByteArrayOutputStream out = new NoCopyByteArrayOutputStream();
    
                RSAEncryptorEngine engine = new RSAEncryptorEngine(rsaKeyPair.getRSAPublicKey());
                OAEPFormatterEngine fengine = new OAEPFormatterEngine( engine );
    
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                System.out.println("2");
                BlockEncryptor cryptoStream = new BlockEncryptor(
                        fengine, out);
                System.out.println("3");
                cryptoStream.write(content, 0, content.length);
                System.out.println("Algorithm: "+cryptoStream.getAlgorithm());
                System.out.println("4");
    
                System.out.println("5");
    //          out.flush();
                System.out.println("Size: "+out.size());
                content = out.toByteArray();
                System.out.println("6");
    //          cryptoStream.close();
                System.out.println("7");
    //          out.close();
    
                System.out.println("8");
                FileUtilities.saveToFile(directoryName + "secureNotes.json", content);
    
                System.out.println("9");
    

    When the software run line System.out.println ("size:" + out.size ()); The result is "size: 0 '.

    If the encryption failed. I checked the file I do: secureNotes.json and it is empty.

    Have anyone checked this http://supportforums.blackberry.com/t5/Java-Development/Use-Advanced-Encryption/ta-p/445085 tutorial is valid anyway? Because I tried to implement my code based on this tutorial.

    You must call out.close before reading its size or bytes.  Call it after your 5th println.

  • Using keys with 4096 bit RSA encryption

    Hello

    I would use encryption RSA 4096 bit on BB device (for the test I use BB 8300 with 4.5.0.52 b75 OS).

    Is this possible?  I am getting exception in this code:

    RSAKeyPair sampleKeyPair;
    sampleKeyPair = new RSAKeyPair (new RSACryptoSystem (4096));

    Change of 4096 by 2048 solve this exception, but it is not the solution for me.

    Thank you.

    I answer myself.

    After reading "Blackberry Enterprise Soluttion Security, Technical Overview", I found that I can use the 4096 bit encryption algorithm, but key generation is limited to 2048-bit (probably performance issue).

    If the problem was not with

    new RSACryptoSystem (4096)

    but with the generation RSAKeyPair.

    I had received an RSA private key from outside, so I need to generate a (at least in the current state of the project I'm working on)

    I'm really curious to know, if someone know how to generate 4096 bit RSA key.

  • RSA encryption

    Hi, I need an example implementation of RSA.

    As shows that I need the implementation of the web page:

    1 hu_RSAParamsCreate

    2 hu_RSAKeyGen

    3 hu_RSAPublicEncrypt / hu_RSAPrivateEncrypt

    I can't get these classes to work.

    I did this process works in Javascritp, but now I need something similar in C++ QT

        var rsa= new RSAKey();
        rsa.readPrivateKeyFromPEMString(pk);
        var hSig=rsa.signString(s,"md5");
        return hex2b64(hSig);
    

    Please, any help will be welcome!

    Thank you!

    I have no examples of these RSA functions at hand, but I think you should be able to see how to use them if you read the following article: http://supportforums.blackberry.com/t5/Native-Development-Knowledge/BlackBerry-10-Using-one-way-encr...

    It uses the same framework of crypto and the different use cases require a very similar code.

    Security Builder user's Guide is the other place to look:

    http://developer.BlackBerry.com/native/documentation/core/com.QNX.doc.crypto/topic/c_sb_ug_overview...

    I hope this helps.

    Martin

  • Decryption and encryption RSA

    Dear Sir
    I would like to encrypt the hash data in the card sent by the host application java applet. I'm Bravo encryption, here my card supports the Protocol T = 0 so what I want is to send the data in an APDU and also to receive data encrypted as a result of the APDU even, is it possible? or I should write two different commands for encryption and encrypted data. ??

    His work, but why it's causing problems? Please explain the reason.

    You can only assign the outgoing APDU once. setOutgoing and setOutgoingAndSend both for this. It's in the doc of the APIs for APDU.

    And also what is the maximum length in return by the method of doFinal()?

    It depends on the encryption algorithm you are using. With RSA encryption, it's the same as the size of the key module.

  • RSA sample code

    I need to some codes examples simple of RSA encryption and decryption.

    Can you help me?

    Thank you.

    Check out these articles in the KB. Maybe you will get some clues.

    How - to use basic encryption

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800779/How_to _...

    How to advanced use of the Encryptio

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800779/How_to _...

    Concerning

    Bika

  • RSA - ENC with EPII HW Accelerator

    Hi all

    I need a confirmation on the following points:

    -rsa - enc is not supported by EPII and modules EPII-Plus, and this is a hardware limitation, so they will not support it in the future either.

    -so rsa - enc is made in the software, while all other uses of encryption is done by the "Accelerator" HW module in the router.

    Thank you

    Attila

    Q. what cryptographic modules support the RSA encryption?

    A. here is the three authentication methods currently available within the IKE policy configuration:

    pre_shared key

    RSA - sig (rsa signatures)

    RSA-BA (nuncios rsa encrypted)

    All three modes are supported on the AIM-VPN/BP, EP, HP and MP-VPN/NM.

    Only the pre_shared and the rsa - sig are supported on the AIM-VPN/BPII EPII, HPII and AIM-VPN/BPII-PLUS, EPII-PLUS and HPII-PLUS. These modules do not support rsa-BA because of the incompatibility between Cisco IOS and hardware of chip crypto API. There is a workaround solution listed in the DDT CSCdv30620notes.

    It is available in this FAQ document

    http://www.Cisco.com/en/us/partner/products/HW/routers/PS282/products_qanda_item09186a00800918fc.shtml#wp40766

  • Encryption supported on MS Module

    Dear all,

    My client has a vpnc 3030 with seven. However, 75% of their traffic is the PPTP protocol. I don't think it's possible to send this through seven. I think that MS doesn't support that SOME and 3DES. Please can someone confirm if this is the case.

    Your help is greatly appreciated,

    Tracey

    The encryption that is not supported by MS algorithm is

    Algorithm RC4

    CBC mode implemented

    40 and 128 key sizes

    Hashing/authentication algorithms

    MD5

    HMAC with MD5

    Public key algorithms

    RSA encryption/decryption (PKCS #1) (Key Wrapping) authorized for use in FIPS mode

    Diffie-Hellman authorized for use in FIPS mode

  • Library of RSA for ExtendScript?

    Hello

    anyone could set up a JS library for RSA encryption in ExtendScript?

    I am using CryptoJS with great success, but it lacks a RSA module. I tried travist/jsencrypt · GitHub with no luck (ExtendScript complains for little things, such as the window and navigator), I'll try digitalbazaar/forge · GitHub too in the next few days.

    Any suggestion is welcome.

    Thank you!

    Davide Barranca

    FYI,.

    • jsencrypt: absence of object window and browser could be circumvented by matching window var = $.global and creating a navigator obj (loan of, say, Chrome)
    • jsrsasign: ugly API
    • Forge: seems to be the best, fast and it works both in JSX side Group server and the library as a node.js module (which was a sine qua non) - could have better documentation, however.

    -Davide

  • problem with authentication RSA on ESX 3.5

    Hi guys,.

    I am trying to configure a SSH + RSA encryption between my ESX Server and my computer connection / Virtual Center.

    The objective here is to make plink command using the root (and after other account + sudo) account but passing without password.

    So I used some of the things that is already inthere,

    "How to create file keypar by dropbear http://..."but it's for ESXi and it use dropbear, which I don't have on ESX 3.5 (Finally I can't ^^).

    So I use the keygen. Here are my actions:

    -Make a ~/.ssh/authorized_keys with rights chmod 700

    -generate public / private keys using the command ssh-keygen-b 1024-t rsa .

    -copy the two files to ~/.ssh/authorized_keys with chmod 700 on them.

    -copy the private key / public, using fastSCP on my PC.

    -generate a ppk file using puttygen.exe

    -change the PuTTY to access my ESX via a root autologon, put my file ppk on SSH auth (with RSA authentication).

    -Save the change

    -exemplary public key to Pageant.exe.

    -change sshd_config to enable RSA / root login

    -try to connect...

    ESX is always ask for a password

    any ideas appreciated!

    Thomas

    Hello

    I am really convinced that it is not a good approach for a production data center to enable root SSH access. Data Center shown here, and I'm testing on is not production data center. It is a test which has by no means of access to the production data center. Two of them have no access to the internet. A quilting my correct computer is always possible, that's why I'm trying to ssh rsa encryption / access work. After I did this job with the root account, be sure to what I'm going to allow it with another account with sudo stuff.

    I would inquire on how get what you want really work and not go the road to get the root work... The same steps apply to any user. But to get the root work, other measures. What you're trying to do is very well known in the Linux space. I use it all the time and never fallen on all issues. To do this, you need to be comfortable with a Linux style editor.

    I don't understand why the publication of a public key is not good? This is not one I will use when it will work, but I assume that a brute force on a 2 with only the public key 1024 RSA key will take a lot of time? (Well I hope)

    It is a good idea never to publish all the keys. Then you need not worry about this...

    Best regards
    Edward L. Haletky
    VMware communities user moderator, VMware vExpert 2009
    ====
    Author of the book ' VMWare ESX Server in the enterprise: planning and securing virtualization servers, Copyright 2008 Pearson Education.
    Blue gears and SearchVMware Pro items - top of page links of security virtualization - Security Virtualization Round Table Podcast

  • Stopped working self-signed certificates

    All a sudden (and not after a Firefox update) 41.0 Firefox stopped accepting SSL certificates self-signed on various websites that it had been accepted for months. I generated certificates myself.

    The link / button to add exceptions and import the certificate has disappeared from the "Untrusted connection" error page

    Things I've tried so far:

    • Import certificates via preferences > advanced > Certificates > view certificates > servers. The imported certificates, but Firefox seems to ignore.
    • Exit Firefox, remove cert8.db in my profile, then restart Firefox
    • Restart Firefox in safe mode
    • Import the certificate in the keychain of the OS (what makes Web sites work on Chrome and Safari)

    Generated certificates are signed "PKCS #1 SHA-256 with RSA encryption", they are not expired and have been generated with

       openssl req -x509 -nodes -days 1095 -newkey rsa:2048 -keyout server.key -out server.crt
    

    In addition to the issue of trust, https://www.ssllabs.com/ssltest/ reported no problems with these certificates, they are fine ("' If trust issues are ignored: has '")

    The only way I can access these sites Web is via a private window: If the certificate has been imported previously (via preferences) private session window accesses Web sites without problem. If the certificate has not been imported, again, I have the option to add a temporary exception and after that is done, it works fine.

    This problem does not appear on another computer, even if the Firefox profile is synchronized between the two.
    The problem does not appear on Firefox 41.0 a colleague (same OS and hardware)
    Certificates signed by a real certification authority are accepted very well.

    UPDATE:

    I have marked this as resolved, but apparently the problem returned once a week, completely randomly.

    The best solution I've found so far is to leave Firefox, delete the following files from my profile, and then restart Firefox:

    • SiteSecurityServiceState.txt
    • cert_override.txt
    • cert8.DB

    Finally, I fixed that by doing a Firefox "Refresh" (under topic: support) and re - sync my profile.

  • TLS fails on linux self-signed certificates

    on firefox 38.1.0 under centOS 6.6 I have some problem with TLS.

    When it first happened I re fact cert using keys of 2048 bytes. It seemed if address the issue when you navigate to similar addresses to https://localhost/somesite, however, I have try https://localhost:10000 with the fact that it still fails:

    An error occurred during a connection to localhost.localdomain:10000. The certificate server included a public key which was too low. (Error code: ssl_error_weak_server_cert_key)

       The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.
       Please contact the website owners to inform them of this problem.
    

    The signing certificate is algorithim-> PKCS #1 SHA-1 with RSA encryption

    The algorithim public key is-> PKCS #1 RSA encryption

    The key has been creating 07/06/15 for a period of 10 years is a Version 1 cert issued by myself with the info
    E = [email protected]
    CN = localhost
    UO = hq
    O = permite
    L = Stone Mountain
    ST = ga
    C = us

    It was a problem of webmin.

    To fix this /etc/webmin/miniserv.pem edition replace the cert and private key sections.

    Use a new generated key and self-signed certificate. If you follow the instructions of centOS, the location of the files are /etc/pki/tls/private/ca.key and /etc/pki/tls/certs/ca.crt

Maybe you are looking for