How to encrypt byte array with out padding using RSA in Java?

I've modulus and public exponent as byte[] array, so I'm trying to convert into BigIntegers and then create public key and then Cipher. Here is the example code:
With this I'm always getting different encrypted bytes, is it because of padding. I dont want to use any padding so what parameter I need to pass along with RSA? I've modulus byte[] array size 64 bytes. I believe I'll get 64 encrypted bytes. I've content size of 32 bytes to be encrypted.
--------code begin ---------------------------
BigInteger bexponent = new BigInteger(pubExpo);
BigInteger bmodulus = new BigInteger(modulus);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(bmodulus, bexponent);
RSAPublicKey pubKey = (RSAPublicKey)keyFactory.generatePublic(pubKeySpec);
Cipher c = Cipher.getInstance("RSA");
c.init(Cipher.ENCRYPT_MODE, pubKey);
return c.doFinal(content);
--------code end---------------------------

With this I'm always getting different encrypted
bytes, is it because of padding. Yes, if you're using PKCS1Padding (which is the default in SunJCE if you don't specify it). Have a look at the PKCS1 spec if you haven't seen it already.
http://www.rsasecurity.com/rsalabs/pkcs
Section 7.2.1 talks about type 2 padding, which uses random bytes as the PS string.
I dont want to use
any padding so what parameter I need to pass along
with RSA? NOPADDING. You should be able to find this out by look at the "Supported Paddings" parameter in your provider's database. Which of course, means you'll need to supply the right number of bytes to the Cipher.

Similar Messages

  • How to make an array with ActiveX Excel using Excel_RangeSetValue2?

    Hello,
    I want to make an array on Excel. For that, I'm using two functions : Excel_WorksheetGetRange and Excel_RangeSetValue2.
    I write the array on Excel file but only the first case of the array is copied.
    Here, a part of my program :
    char * DataToWrite = {"A", "B", "C", "D"}
    char cCell[10];
    VARIANT             vCell, Data;
    ExcelObj_Worksheet hWorksheet;
    ExcelObj_Range      hRange;
      CA_VariantSetCString (&vCell,cCell);        //cCell = A1:A4
      Excel_WorksheetGetRange (hWorksheet, NULL, vCell, CA_DEFAULT_VAL, &hRange);
      CA_VariantSetCString (&Data,DataToWrite );
      Excel_RangeSetValue2 (hRange, NULL, Data);
    Here what I obtain when I'm compiling on Excel file :
    A
    A
    A
    A
    Solved!
    Go to Solution.

    You should use other instructions to fill the range of cells:
    strcpy (msg, "A1:A4");
    CA_VariantSetCString (&MyVariant, msg);
    Excel_WorksheetRange (ExcelWorksheetHandle, NULL, MyVariant, CA_DEFAULT_VAL, &ExcelRangeHandle);
    Excel_RangeActivate (ExcelRangeHandle, NULL, NULL);
    // Create a SafeArray from array of data
    CA_VariantSet2DArray (&MyVariant, CAVT_CSTRING, righe, 1, array);
    // Transfer data to Excel range
    Excel_SetProperty (ExcelRangeHandle, NULL, Excel_RangeValue2, CAVT_VARIANT, MyVariant);
    ClearObjHandle (ExcelRangeHandle);
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • I have like five GB's of ghost data (data the device claims is not there but it is still taking up space) on my I pad 2 from a failed movie download attempt. How do I fix that with out resting my iPad? I have only 1GB left of storage

    I have like five GB's of ghost data (data the device claims is not there but it is still taking up space) on my I pad 2 from a failed movie download attempt. How do I fix that with out resting my iPad? I have only 1GB left of storage
    The movie had gotten to the point that I could watch it all the way through but it still said processing and got stuck at that point and when I turned off the wifi to try to restart it, it deleted its-self but did not free up any of the storage It was taking up
    Restarting my iPad does not help
    Some thing similar also happened to my old laptop when trying to download the iOS 5 update to my laptop when it came out. It kept getting disconnected and every time it would try to start over and act like what had already been downloaded was not there though it was still taking up the storage space.
    And it continued repeating until it took up all of my storage space. The data file would not show up anywhere so I had to restore my laptop to the factory settings and that worked for awhile but I eventually had to get a new laptop.

    Did you try to set it up as new device, as explained in this article?
    How to erase your iOS device and then set it up as a new device or restore it from backups
    If this does not work, use iTunes to set it back to factory settings, which would also install the latest software:
    Use iTunes to restore your iOS device to factory settings - Apple Support

  • How to add byte[] array based Image to the SQL Server without using parameter

    how to add byte[] array based Image to the SQL Server without using parameter.I have a column in table with the type image in sql and i want to add image array to the sql image column like below:
    I want to add image (RESIM) to the procedur like shown above but sql accepts byte[] RESIMI like System.Drowing. I whant that  sql accepts byte [] array like sql  image type
    not using cmd.ParametersAdd() method
    here is Isle() method content

    SQL Server binary constants use a hexadecimal format:
    https://msdn.microsoft.com/en-us/library/ms179899.aspx
    You'll have to build that string from a byte array yourself:
    byte[] bytes = ...
    StringBuilder builder = new StringBuilder("0x", 2 + bytes.Length * 2);
    foreach (var b in bytes)
    builder.Append(b.ToString("X2"));
    string binhex = builder.ToString();
    That said, what you're trying to do - not using parameters - is the wrong thing to do. Not only it is insecure due to the risk of SQL injection but in the case of binary data is also inefficient since these hex strings are larger than the original byte[]
    data.

  • How to add Excise item with out chapter id

    Dear all,
    How to add Excise item with out chapter id?
    Chapter id of purchae items will be known only after receiving Invoice/gate pass/delivery  chalan from supplier/vendor
    To send a purchase order we need to create that particular item in the master, but with out assigning chapter id system is  not allowing to save without chapter id.
    How to solve this?
    I am with SAP 8.8 and PL 10
    Thanks in advance
    regards,
    Kumar

    Hi Kumar,
    Refer the book of chapter ID or find out on internet you will get the chapter ID.
    Still if you not able to get  the chapter id then consult with excise advisory.
    But you can add Excise PO until you have the excise details in Item master.
    Regards,
    Datta Kharat

  • How to create shipment document with out inbound delivery document

    Dear Friends
    How to create shipment document with out outbound/inbound delivery document.
    In my client scenario, there is no inbound delivery for normal purchases.
    Just there are raising the PO to vendor, then they are doing MIGO for goods receipt.
    Can we do shipment creation with reference to PO?
    If it is possible, how it will be?
    Please let it solve
    With regards
    Lakshmikanth

    Dear Sameer,
    Please go to transaction VT01N here you enter Transportation planning point and shipment type then press enter.
    Now system will take you to the shipment document creation screen here you click on Select deliveries or press F6 now system will take you to the select outbound deliveries screen in this screen you enter selection data then execute, now deliveries will get assigned to that shipment.
    After assigning the deliveries enter the remaining data then complete the shipment finally save the shipment document.
    For more information please go through this SAP help link
    Note:- Shipment process need to be carry out for the deliveries before PGI.
    http://help.sap.com/saphelp_47x200/helpdata/en/f5/04898047bd11d2bf750000e8a7386f/frameset.htm
    I hope this will help you,
    Regards,
    Murali.

  • I cant remember my password to logon to my mac, how can i change it with out needing the old one?

    i cant remember my password to logon to my mac, how can i change it with out needing the old one?

    http://support.apple.com/kb/HT1274

  • I have an itunes account on my home PC. I want to use my same account but on my laptop. How do i do this with out wiping out my phone and backing up all my Pictures and Apps? Please Help.

    I have an itunes account on my home PC. I want to use my same account but on my laptop. How do i do this with out wiping out my phone and backing up all my Pictures and Apps? Please Help.

    Copy everything from the old computer or your backup copy of your old computer to your new one.
    Type "move itunes library from pc to mac" or similar into the google search bar.

  • If i have already logged in my iTunes with my iPod and plugged that in, but now i have a new iPod and I want to plug that in to my laptop how would i do that with out losing anything on my new iPod and my old one. Both my ipods are on different accounts?

    If i have already logged in my iTunes with my iPod and plugged that in, but now i have a new iPod and I want to plug that in to my laptop how would i do that with out losing anything on my new iPod and my old one. Both my ipods are on different accounts?

    Nothing special. See:
    How to Set Up Two iTunes Accounts on One Computer | Chron.com
    iTunes: How to share music between different accounts on a single computer

  • I have had my laptop stolen, and am trying to up load my music from my iphone to a new computer but how do i do it with out loosing everything?

    I have had my laptop stolen, and am trying to up load my music from my iphone to a new computer but how do i do it with out loosing everything?

    See this support article:
    http://support.apple.com/kb/HT1848
    You can also download most of your content again from the iTunes Store:
    http://support.apple.com/kb/ht2519
    For content not purchased from the iTunes Store, check out this post from Zevoneer for some iPod/iPhone media recovery options:
    http://discussions.apple.com/thread.jspa?messageID=10570955#10570955
    Regards.

  • How to build a array with high sampling rates 1K

    Hi All:
    Now I am trying to develop a project with CRio.
    But I am not sure how to build a array with high sampling rates signal, like >1K. (Sigle-point data)
    Before, I would like to use "Build Arrary" and "Shift Register" to build a arrary, but I found it is not working for high sampling rates.
    Is there anyother good way to build a data arrary for high sampling rates??
    Thanks
    Attachments:
    Building_Array_high_rates.JPG ‏120 KB

    Can't give a sample of the FPGA right now but here is a sample bit of RT code I recently used. I am acquiring data at 51,200 samples every second. I put the data in a FIFO on the FPGA side, then I read from that FIFO on the RT side and insert the data into a pre-initialized array using "Replace Array subset" NOT "Insert into array". I keep a count of the data I have read/inserted, and once I am at 51,200 samples, I know I have 1 full second of data. At this point, I add it to a queue which sends it to another loop to be processed. Also, I don't use the new index terminal in my subVI because I know I am always adding 6400 elements so I can just multiply my counter by 6400, but if you use the method described further down below , you will want to use the "new index" to return a value because you may not always read the same number of elements using that method.
    The reason I use a timeout of 0 and a wait until next ms multiple is because if you use a timeout wired to the FIFO read node, it spins a loop in the background that polls for data, which rails your processor. Depending on what type of acquisition you are doing, you can also use the method of reading 0 elements, then using the "elements remaining" variable, to wire up another node as is shown below. This was not an option for me because of my programs architecture and needing chunks of 1 second data. Had I used this method it would have overcomplicated things if I read more elements then I had available in my 51,200 buffer.
    Let me knwo if you have more qeustions
    CLA, LabVIEW Versions 2010-2013
    Attachments:
    RT.PNG ‏36 KB
    FIFO read.PNG ‏4 KB

  • How to print a string with out using main method??

    how to print a string with out using main method??
    if we can tell me with example?
    thanks in adavance
    raja

    Hi,
    actually there's none. The UITableView class needs to "know" the tableView's height so either it can calc <number of rows> times <row height> or it has to sum the height of each single row.
    If the row which needs to be of different size always is the first or the last row you can user a tableHeader or tableFoot view.
    Regards
    Dirk

  • How to populate an array with random text files.

    I am making a Jeopardy program. I have my program set up so that it retrieves 5 random text files. I just want to know how I populate one array with all the lines from the text files my program is retrieving.

    You can read a textfile line by line and add each line to an ArrayList. An ArrayList is very much like an array only that it's "open ended". You can start adding lines without first knowing how many you're going to get. If you still want an ordinary "static" array when you're finished reading lines you can easily get one from the ArrayList and then drop the ArrayList.

  • How to create 2D array with 3 rows and unlimit column?

    how to create 2D array with 3 rows and unlimit column?

    Here are images of what I described in my previous post
    Message Edited by JoeLabView on 11-14-2007 07:56 AM
    Attachments:
    2D-array_code.PNG ‏7 KB
    2D-array_values.PNG ‏13 KB

  • How can i get apps with out using credit card info because i do not have a card ?

    how can i get apps with out using credit card info because i do not have a card ?

    Yo Chris. I've been following your answers to different threads and quite frankly, you're very keen in answering everybody regarding this stupidity that Apple has brought upon its customers. Kudos to you. But the problem is, most of the time, in some devices, your solution doesn't work because the NONE option is not there. The same goes for me.
    Meanwhile, I found a temporary workaround for the iPhone 4s, iPad 2 and iPod Touch 4th Gen.
    Register a free Apple ID from the iCloud Settings.
    Go to Settings>iCloud>Account>Tap Payment Information on the Storage Plan Category.
    Fill in the other boxes and choose "None" on Credit Card Information.
    That's it! Hope I helped those who still couldn't find the "None" Option.
    Must be running IOS 5.0.1 though, else there would be no iCloud.

Maybe you are looking for

  • Feed Bridge from Access or Excel speadsheet??

    Hi - This is a Bridge question so I hope I'm in the best forum for an answer. I have a huge image database (3000+) in MS Access.  My supervisor wants to customize it.  By the time he was finished describing his wish list it sounded like he wanted to

  • Adobe Flash Player wont work after all steps taken, what haven't I done to make it work?

    I tried to play a game I love & I got this message: "To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed" So I went to your site to update my flash player & hit the "Test Flash Player" button & it came up like this

  • 60W charger for 15 inch Macbook Pro?

    Hi, it is finals time and my 85W Macbook Pro charger has just decided to quit on me. My friend is selling her 60W charger that she uses on her 13 inch Macbook Pro...can I buy it and use it on my 15 inch one? Thanks!

  • The display problem in Issue management in Solman

    Hi When i try to log in a defect from the Test script status in STWB _WORK , my screen on the top menu looks like ???????????????????? . Functionally it's alrite but do u know how i can get rid of ??????????? .

  • Are there any more advanced search features for "ctrl+f" (find in page)?

    I'm very limited by the current test search features. And I'd like to see some advanced features like: 1) I HATE that the find bar disappears all the time. I would like it to be visible all the time -- not disappear when I change tabs, or open a new