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

Tags: BlackBerry Developers

Similar Questions

  • 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

  • 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.

  • 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.

  • 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.

  • Wireless LAN on Equium A210-1AS connection with WPA-TKIP encryption problem

    I have a 1AS Equium A210 with Vista but cannot connect to the internet via a wireless router cable modem NTL using WPA-TKIP encryption and 5600 philips.

    The laptop shows the base station wireless with a beep sound intense but said that the base of the station is not responding or is hidden when I try to connect to the internet.

    I'm using the correct password.
    I am able to connect to the internet via the base station when connected via the ethernet cable. Other old computers connect wireless with no problems.

    I heard that some combinations of chipsets with Vista can be the cause of some of these issues.

    Clear advice or ideas on what I could try to get wireless internet would be greatly appreciated.

    Have you checked to connect the laptop to the router WLan with WPA encryption settings? Please do. You must disable the WLan encryption to test the WLan connection

    If the laptop could connect properly, then encryption is certainly the reasons why the laptop can not establish the WLan.

    Maybe your wireless network card does not like this on the encryption support or you simply have to update the Windows operating system and the driver WLan.

  • zBook 15 - SSD encryption problem

    Good afternoon everyone,

    I get the error message below.

    "An error occurred during initialization authentication pre-seed. (0x9a00).

    The problem is the following:

    1. Image, pushed to the machine using the Clonezilla software. It is a standard construction we have on most laptops.
    2. On-board HP encryption enabled. Recovery stored on USB key.
    3. Laptop has been used for a few weeks.
    4. Someone tried to install software of BeCrypt encryption on the machine.
    5. This, as expected (I wish they'd asked first), completely messed up the machine.
    6. When starting, we still got the encryption authentication screen. After the password, he would try to start windows and BSOD.
    7. To try to remedy the situation, I entered the password encytption and before she started windows, open a CMD window.
    8. Using DiskPart I wiped the drive and reinstalled Windows 7 from CD.
    9. The machine worked, would start through encryption (password entered as usual) and then in the new installation of Windows 7.
    10. Thinking that everything was OK, I relayed the Clonezilla image once more (without disabling the encryption)
    11. The machine now give the error at the top of the pole and the recovery key refuses to play ball

    No matter what anyone thinks could work to solve this problem and save the SSD?

    Thanks in advance

    FN

    Hi fenewman,

    Your ZBook 15 is a commercial product and get your question more exposure, I would say post in the trade forums. Here is a link to the forum Commercial Notebook.

    Thank you

  • XTEA encryption problems

    I'm trying to implement the XTEA encryption for a project, but the values that I receive does not correspond really. Is there a known problem with this implementation

    http://www.NI.com/white-paper/7520/en/

    I managed to solve the problem. The encryt implementation, mentioned in vi is false, and all you have to do is to remove the forloop and send data directly key.

  • 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

  • BlackBerry Curve 9300 encryption problems with files *.rem smartphone

    Hi all

    I encrypted my phone by using the password. Also encrypted Media card with included media files.

    Now I want to save the photos on my media card, but all are in *. jpg.rem extension. I tried to disable the encryption but the *. jpg.rem remains.

    My camera works fine and I have my password (thank God for the tht).

    All the post I saw up to present r guy who changed phones or don't remember password.

    I don't have the option of emailing photos for me, as the files I need total 167 MB.

    I'm on BB Curve 9930

    Please help guys...

    Thnx

    OK it got...

    The following things were made by me:

    (1) options-> memory-> Compression disabled.

    (2) options-> memory-> Support of = OFF mass storage Mode

    (3) options-> memory-> security--> encryption--> Media Care active =

    (4) options-> memory-> security--> encryption--> media files include = NO

    I left the encryption ON. Just like before.

    Then the phone connected to the laptop. Password on the phone and in the BBDesktop software entry.

    Presto...

    IM can transfer all the unenctrypted of pictures and videos with *.rem to my HARD drive.

    Hope this helps other ppl have this problem.

  • Dell Data Protection encryption problem

    Security framework for the DDP client, authentication and security tools tools have been uninstalled and we now cannont access our outlook documents or spreadsheets files.  Something was wrong with the uninstall, and we can't do a system restore to get it back.  Any help would be greatly appreciated.  All the files are locked and we have this problem as soon as possible.  Thank you very much.  The owner of the laptop can be contacted at If the laptop computer access is necessary.

    Thanks for your help in advance,

    Lee

    Dell support has finally got to level 3 or 4 they and used a (locksmith) program files unlocked.  The laptop will have to be re-partitioned, reformatted and windows reinstalled to the laptop on the right.  It works but has errors at startup and do other functions but not terribly annoying because the files could be recovered without encryption.

  • RSA key problem

    I'm working on a project of authentication and I have a weird bug. (This is my first project on JavaCards).

    The problem is that I am not a different length of 512-bit RSA key. I load the application on emulated map. Here is the code

    try {}
    KeyM = new KeyManager ((short) 1024);
    } catch (Exception e) {}



    Public RSAKey(short size) throws Exception {}

    bufferA = new ubyte [size];
    bufferB = new ubyte [size];

    paireDeClef = new KeyPair (KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_1024);




    paireDeClef.genKeyPair ();
    publicKey = (RSAPublicKey) paireDeClef.getPublic ();
    privateKey = (RSAPrivateKey) paireDeClef.getPrivate ();

    CIP = Cipher.getInstance (Cipher.ALG_RSA_PKCS1, false);
    }

    I already tried to throw a CryptoException... He didn't show me any error message.
    Am I using try catch correctly?


    All my thanks!

    No, you're not. You catch the exception and even printing. If you have no idea why it does not work.

    Never do this.

    Print the stack trace and post it here if it's not always you enlighten.

  • 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

  • Bouncy Castle encryption problem

    Hello

    I want to add bouncy castle APIs in my blackberry JDE project, the problem is the file jar is added to the project, but if I tried to import any class in the castle of org.bouncy show the error like package does not exist...

    I tried the same thing in eclipse too but in the fact that she successfully added, but no use...

    I tried with adding another project of library also...

    By changing the names of packages and new recompile the java files, my problem has benn fixed

  • Encrypted problem

    Mr President, I got Windows7 installed on my machine. I have some encrypted files by using the right click. Then I got Windows7 and again once installed. But now I am unable to access. It shows that you don't have the permission to access. Help, please

    Mr President, I got Windows7 installed on my machine. I have some encrypted files by using the right click. Then I got Windows7 and again once installed. But now I am unable to access. It shows that you don't have the permission to access. Help, please

    BitLocker is good. It does not distinguish between a foreigner and you. You have a certificate or you can't read encrypted files (which is exactly what you had in mind when you your files encrypted). Take a look at this thread Bitlocker topic:
    http://social.answers.Microsoft.com/forums/en-us/w7security/thread/19f28028-EACE-4878-b5e5-8cd78c19f6f3
    The only way you'd be able to use your encrypted files would be if you have saved your file recovery certificate and your certificate of personal encryption (and private keys) and the data recovery agent certificate to regain access.
    BitLocker Repair tool to recover a disk
    http://TechNet.Microsoft.com/en-us/library/ee523219 (WS.10) .aspx

Maybe you are looking for

  • I have a black area where I should be able to minimize Firefox.

    Running Firefox 34.0 and says that I need to update. Have tried safe mode, still the minimise tab(?) in upper right corner of screen is black. No other black screens. I tried to download Firefox again, but it says I already have Firefox Latest versio

  • Access the page Add-ons is defective for https

    Since a recent update of Firefox whenever I use the Google search provider in the search bar that fails because it uses the https protocol. I removed the Google search engine and tried to re - install it but when I click on the link "Get more search

  • Satellite U400 - error - Bluetooth is not started

    I used my u400 3 months without problem...Then all of a sudden happened several problems with bluetooth... When I tried to use BT for example OBEX, I got the error msg: "Bluetooth has not begun."I tried to reinstall the driver for bt, but I couldn't.

  • I do or Don't I have bluetooth?

    Hey guys,.When I go into my device manager it comes up with (under bluetooth) Bluetooth RFCOMM from toshiba...without that it means that I have the bluetooth because whenever I have try and access it, it shows generally could open acpi etc etc blueto

  • I lost my password hwsetup

    Please help me! I forgot the password for hwsetup in my Toshiba tecra A1 laptop. If anyone can help me, maybe there are some universal passwords or something like that. Thanks for your help Lukas