How to encrypt more than 117 bytes with RSA?

Hi there,
I am struggling to encrypt more than 117 bytes of data with a 1024 bit RSA key.
If I try to encrypt (write to my OutputStreamWriter) 118 Bytes ("A"s) or more, the file I am writing to is just empty and I get an exception whe trying to read it.
I know the encryptable bytes (blocksize) are related to the key length: blocksize = keylength / 8 -11
I also know RSA encryption of large files is discouraged, because it is like 100x slower than for instance AES and was originally only intended to exchange symmetric keys.
Still I need to be able to asymmetrically encrypt at least 5kb of Data.
I am out of ideas here and have no understanding of why the block size is limited (i know from hours of "googling" that it is limited as described above though).
So, I would be very glad If somebody could point out a way how I could encrypt more than 117 bytes (without using a longer key of course).
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.Reader;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.security.PublicKey;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import javax.crypto.*;
public class strchrbty {
     public static void main(String[] args) {
          //generate Keys
          PublicKey publicKey = null;
          PrivateKey privateKey = null;
          try {
               KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
               kpg.initialize(1024);
               KeyPair kp = kpg.generateKeyPair();
               publicKey = kp.getPublic();
               privateKey = kp.getPrivate();
          } catch (NoSuchAlgorithmException e) {
               e.printStackTrace();
          //------ENCODE------
          try {
              //initialize cipher
              Cipher cipher = Cipher.getInstance("RSA");  
               cipher.init(Cipher.ENCRYPT_MODE, publicKey);   
               OutputStream cos = new CipherOutputStream(new FileOutputStream("c:\\test.txt"), cipher);
              Writer out = new OutputStreamWriter(cos);
              // 1024 bit (key length) / 8 bytes - 11 bytes padding = 117 Bytes Data.
              //  for 118 Bytes (or more) Data: c:\\test.txt is empty annd no Data is read.
              for(int i = 0; i<117; i++) {
                   out.write("A");
              out.close();
              cos.close();
         } catch (InvalidKeyException e) {
              e.printStackTrace();      
         } catch (NoSuchPaddingException e) {
              e.printStackTrace();           
         } catch (NoSuchAlgorithmException e) {
              e.printStackTrace();      
         } catch (IOException e) {
              e.printStackTrace();
         //------DECODE------
         try {
              StringBuffer buf = new StringBuffer();
              Cipher cipher2 = Cipher.getInstance("RSA"); 
              cipher2.init(Cipher.DECRYPT_MODE, privateKey);
              //read char-wise
              InputStream cis = new CipherInputStream(new FileInputStream("c:\\test.txt"), cipher2);
              Reader in = new InputStreamReader(cis);
              for(int c = in.read(); c != -1; c = in.read()) {
                buf.append((char)c);
              //output
              System.out.println(buf.toString());
              in.close();
              cis.close();
          } catch (InvalidKeyException e) {
              e.printStackTrace();      
         } catch (NoSuchPaddingException e) {
              e.printStackTrace();           
         } catch (NoSuchAlgorithmException e) {
              e.printStackTrace();      
          } catch(IOException e) {
             e.printStackTrace();
}Regards.
Edited by: junghansmega on Sep 10, 2008 3:41 PM
Sorry about the bad autoformating.... It only occurrs in here, in my eclipse it looks fine =(

junghansmega wrote:
Hi there,
I am struggling to encrypt more than 117 bytes of data with a 1024 bit RSA key.
If I try to encrypt (write to my OutputStreamWriter) 118 Bytes ("A"s) or more, the file I am writing to is just empty and I get an exception whe trying to read it.
Good, it should be painful.
>
Still I need to be able to asymmetrically encrypt at least 5kb of Data.
In this forum, 99.999% of the time this kind of claim is due to a lack of understanding of the role of public key cryptography.
I am out of ideas here and have no understanding of why the block size is limited (i know from hours of "googling" that it is limited as described above though).
It should not be difficult to break up the input into 117 byte chunks and encrypt each chunk through a newly initted cipher object. Of course you will have to be very careful in properly encoding the output. You might naively think that the output is always 128 bytes, but is that true? Might it be 127 bytes sometimes? Maybe even 126 bytes?

Similar Messages

  • How to get more than 256 bytes data

    hello.
    I use Schlumberger 32K Card�iJava Card 2.1�j.
    Please tell me how to get more than 256 bytes data from the applet in the card!!
    According to JCRE specification, need to use Get Response Command.
    What is Get Response command?
    Do I have to write processing of Get Response command to an applet?
    Or JCRE processes Get Response command?
    If knows, please tell me about!!
    Thanks.

    Thanks for your response!!
    I understand that I have to write processing of Get Response command to an applet.
    But case of Schlumberger 32K card, when host send Get Response command to an applet, card reply 6F-00!?
    I'm investigating now, and it seems that response is returned before applet processes Get Response command(CLA = 00, INS = C0).
    Do JCRE perform the process of Get Response command?

  • How to display more than one column with for each

    Hi guys,
    how to display more than one column with for each like below?
    for each
    Item1
    Item2
    Item3
    Item4
    Item5
    Item6
    Item7
    Item8
    Item9
    Item10
    End for each
    for each          
    Item1     Item2     Item3
    Item4     Item5     Item6
    Item7     Item8     Item9
    Item10          
    End for each

    Take a look at this to see if the solution provided would work for you: https://blogs.oracle.com/xmlpublisher/entry/multi_column_row_woes
    Won't you have more than 10 records in your data file ? If you are going to have only 10 items then you may be able to use position() function to limit it to 3 each..
    Take a look at this: https://blogs.oracle.com/xmlpublisher/entry/turning_rows_into_columns
    Thanks,
    Bipuser

  • How to insert more than 4000 bytes in BLOB column

    Hi all,
    My oracle version is Oracle Database 11g Enterprise Edition Release 11.2.0.3.0.
    I have checked in google and in this forum also, but did not find the answer.
    When inserting into less than 4000 bytes, it is inserting without any issues. If i am inserting more than that, it is throwing
    error like this ORA-01460: unimplemented or unreasonable conversion requested.
    Can anybody guide me how to do this or link.
    Thanks in advance.
    Thanks,
    Pal

    user546710 wrote:
    Hi,
    Thank you very much for your reply.
    Before, I have not worked with BLOB column, so I don't know much about its using. Currently, I am using direct
    insert statement only. Its a normal stored procedure written in a package. I am calling this SP with other columns and
    with this BLOB column. I am able to insert into table, if the inserted file is less than 4000 bytes. If it is more than that,
    I am getting that problem.
    Thanks,
    VenuSQL variables can only hold 4000 bytes.
    PL/SQL can hold up to 32767
    I am getting that problem. 100% lacking in actionable detail
    post code & COMPLETE error message & code

  • How to scan more than one page with Acrobat 9, Windows 7?

    I have Acrobat 9 Standard, with Windows 7, and am trying to scan from an HP LaserJet 3015.  Prior to having Windows 7, there were no problems.  Now when I scan only one page will show as a pdf, no matter how many I scan.  The data shows "transferring" after each page, but only one shows up to save.  The printer has the most up to date drivers.  I have tried as a preset scan or custom scan, with the native mode and the memory mode, in all configurations, but nothing seems to help.  What to do?

    Yes.  The drivers for the printer, and Acrobat have been updated.  I even double checked today.  Still no luck.  I tried in memory mode, native mode, with pre-configured settings and with custom scan.  Scans one page really good, but no more unless I add them on which is VERY time consuming. 
    Connie Hoffmann
    The Law Office of Marilyn G. Miller
    PO Box 917
    151 Loop 64 East, Suite D
    Dripping Springs, Texas 78620
    Telephone 512-894-0319
    Facsimile  512-894-4010

  • Selection Screen - How to populate more than 1 field with help input

    Hello all,
    I have a selection screen in which 4 fields are defined.
    Help input is available for the first field. On selecting the entry in the popup, I would like the 4 fields to be populated with the corresponding values.
    Try transaction CV01 for a sample of what I want:
      Selecting from the popup will populate all 4 fields.
    Thanks in advance,
    Alain Cyr.

    Please see the following program,  it should show you exactly what you need to do.
    report zrich_0002 .
    parameters: p_bukrs type t001-bukrs,
                p_butxt type t001-butxt,
                p_ort01 type t001-ort01,
                p_land1 type t001-land1.
    data: dynfields type table of dynpread with header line.
    data: return type table of ddshretval with header line.
    at selection-screen on value-request for p_bukrs.
      call function 'F4IF_FIELD_VALUE_REQUEST'
           exporting
                tabname           = 'T001'
                fieldname         = 'BUKRS'
                dynpprog          = sy-cprog
                dynpnr            = sy-dynnr
                dynprofield       = 'P_BUKRS'
           tables
                return_tab        = return
           exceptions
                field_not_found   = 1
                no_help_for_field = 2
                inconsistent_help = 3
                no_values_found   = 4
                others            = 5.
      read table return with key fieldname = 'P_BUKRS'.
    * Add it back to the dynpro.
      dynfields-fieldname = return-retfield.
      dynfields-fieldvalue =  return-fieldval.
      append dynfields.
    * Get the company code from db and add to dynpro
      data: xt001 type t001.
      clear xt001.
      select single * into xt001
             from t001
            where bukrs = return-fieldval.
      dynfields-fieldname = 'P_BUTXT'.
      dynfields-fieldvalue = xt001-butxt.
      append dynfields.
      dynfields-fieldname = 'P_ORT01'.
      dynfields-fieldvalue = xt001-ort01.
      append dynfields.
      dynfields-fieldname = 'P_LAND1'.
      dynfields-fieldvalue = xt001-land1.
      append dynfields.
    * Update the dynpro values.
      call function 'DYNP_VALUES_UPDATE'
           exporting
                dyname     = sy-cprog
                dynumb     = sy-dynnr
           tables
                dynpfields = dynfields
           exceptions
                others     = 8.
    start-of-selection.
    Welcome to SDN!  Please remember to award points for helpful answers and mark you post as solved when solved completely.  Thanks.
    Regards,
    Rich Heilman

  • HT202213 How can I authorize more than 5 computers with the same Apple ID?

    Somebody knows how to authorize more than 5 computers with the same Apple ID? I have One Apple IMac, Apple TV, I-PAD, 2 HP PC's, One I-Phone and one I-Pod Touch. I would like to have the possibility to use as I wish the same Apple ID on one of those without deauthorizing another one.

    "Somebody knows how to authorize more than 5 computers with the same Apple ID? "
    You cannot.
    Authorization applies ONLY to computers.  Ipods/ipads/iphones/Apple TVS are NOT authorized at all.

  • How can i use Itunes to update more than one IPad with more than one owner

    How can i use Itunes to update more than one IPad with more than one owner?  I own an IPad and my wife owns an IPad.  I want to use my system to update both IPads.  We have different Apple Accounts and different applications.  Is this possible?

    Of course, that is too easy.  I am such a bonehead.

  • Can anyone give me simple instructions on how to use more than one ipod on the same computer with itunes? Both my daughters have ipods, my wife has one

    Dear All
    Can anyone give me simple instructions on how to use more than one ipod on the same computer with itunes. My daughters have a different generation 'nano' each & my wife a 'shuffle'?
    Many thanks

    Click here for options.
    (69081)

  • Tables with more than one cell with a high number of rowspan (ej. 619). This cell can not be print in a page and it must be cut. But I don't know how  indesign can do this action.

    Tables with more than one cell with a high number of rowspan (ej. 619). This cell can not be print in a page and it must be cut. But I don’t know how  indesign can do this action.

    set the wake-on lan on the main computer
    The laptop's too far away from the router to be connected by ethernet. It's all wifi.
    No separate server app on the laptop, it's all samba
    The files are on a windows laptop and a hard drive hooked up to the windows laptop. The windows share server is pants, so I'd need some sort of third party server running. Maybe you weren't suggesting to use Samba to connect to the windows share though?
    I'm glad that you've all understood my ramblings and taken and interest, thanks The way I see it, I can't be the only netbook user these days looking for this kind of convenience, and I certainly won't be once chrome and moblin hit the market.
    Last edited by saft (2010-03-18 20:38:08)

  • How to perform Text length more than 4000 bytes

    I want to read each row from txt file
    and used utl_file pacage to concat contents into a variable,
    the variable datatype is varchar2(4000), so text length can't more than 4000 bytes,
    but I wish get full text from txt file, How can I do?

    Thans! Detlev.
    I have a code :
    PROCEDURE read_file( path in varchar2, filename in varchar2, msg in out varchar2) AS
    data_line varchar2(4000);
    ifile utl_file.file_type;
    BEGIN
    ifile := utl_file.fopen(path,filename,'R');
    LOOP
    utl_file.get_line( ifile, data_line);
    msg := msg | | rtrim(data_line);
    END LOOP;
    utl_file.fclose(ifile);
    EXCEPTION
    WHEN no_data_found THEN
    utl_file.fclose(ifile);
    END;
    My question is
    1. The msg length can't more than 4000
    2. I use utl_raw.cast_to_raw function, that can't cast varchar2 to raw if varchar2 length more than 2048
    3. If I want to change the data type varchar2 to raw,
    the utl_raw.concat function can't use Loop ....end loop clause,
    So that only use utl_raw.concat(ra1, ra2,ra3,ra4,ra5, ... ra12)
    I want to concat all line to a raw datatype from text file , How can I do?

  • How to authorise more than one machine (1 tablet Android and one PC running Windows XP Pro) with the same Adobe ID ?

    How to authorise more than one machine (1 tablet Android and one PC running Windows XP Pro) with the same Adobe ID ?

    Cloud License allows 2 activations http://www.adobe.com/legal/licenses-terms.html
    -Install on a 2nd computer http://forums.adobe.com/thread/1452292?tstart=0
    -Windows or Mac does not matter... 2 on the same operating system, or 1 on each

  • How do I send more than 1 photo with an email using iPhoto5?

    Hello,
    I'm able to select a single photo and send an email. However I can't find how to select more than 1.
    When I select another photo the first one is unselected. I've tried dragging one onto the next and no luck. The 'help' says select the photos you want, but doesn't say how?
    I'm using iPhoto 5.0.4 with an eMac using OSX 10.4.11.

    doverrog
    To do a multiple select: Hold the  key and click
    To select a contiguous group of objects: Click on the first one then hold the Shift Key and click on the last. All the items in between will be selected.
    These work throughout the OS.
    Regards
    TD

  • How can I make more than one account with chat on clubwpt?

    I can't make more than one account with chat on clubwpt? i know several players that has made as many as 20 accounts with chat.I can make accounts but clubwpt will not give me chat,they must have my IP address ,because their response is " you r allowed one account with chat only." But as I have said several players have several accounts with chat. Can anyone help me? Are there any programs or plugins that can do this?Any help at all will be greatly appreciate.

    Open another iCloud account for the other user.

  • How to show more than one record at a form-like style report?

    Hi All,
    I developed a form-like style report
    I want it to show more than one record at once (At the same page)
    I tried that by setting the value to "Maximum records per page" property for the repeating frame to 10
    but when I close the property palete and open it agian the value is returned to 1 !!!
    how to show more than one record at the same page?????
    Thank u

    Hi,
    there's perhaps another property like "page protect". If than 2 records didn't fit at one page there's a page break. Or is there any object inside the repeating frame with page-break properties? Sorry .. it's like looking into a chrystal ball ...
    Regards
    Rainer

Maybe you are looking for

  • Vendor partner not coming in on PO

    We have an issue where a vendor is partnered with another vendor for the invoicing party, so when you look at the vendor master record for vendor XXX, the invoicing party is vendor 123.  When creating a PO without referencing a PR, the correct invoic

  • Error in Displaying table.

    Hello Friends,                       I am populating a in a table in one view, getting values in another view. I am using separate context node for getting the value and adding these values into another context node, which is the source for the table

  • Re : batch input programming..

    hi friends is it possible to use the call transaction and session the scenario described. 1. like i am having two record sets corresponding to two transactions and i want them to be uploaded using 'call transaction' for one transaction and 'session'

  • Bug: Changing line does not change legend

    Hello, I am almost certain this is a bug but hopefully I've done something wrong. Basically, I am printing a chart in black and white and I want one line to be dashed and the other solid. When I do this in numbers, the key/legend is not updated. Both

  • Travel Calendar/Weekly Report/Travel Expense Manager

    Hi, Can any body explain me what is the difference between Travel Calendar, Weekly Report and Travel Expense Manager and for which type of trips i can use teh above forms. Regards, Sundar