Byte array size changes

For some reason the size of my byte arrays change, and it is causing problems using an AES Cipher.
The length of the byte array is 16 when I first encrypt text, but when I try and decrypt it, it tells me the length is 29. Then I have an IllegalBlockSizeException.
Can someone explain how to overcome this problem?
I used the UTF-8 encoding on Ubuntu 8.04

TamalinJava wrote:
For some reason the size of my byte arrays change, and it is causing problems using an AES Cipher.A byte[] has a fixed size, you cannot change it.
The length of the byte array is 16 when I first encrypt text, but when I try and decrypt it, it tells me the length is 29. Then I have an IllegalBlockSizeException.
I used the UTF-8 encoding on Ubuntu 8.04This is your problem. It translates values >= 128 to be two characters.
Can someone explain how to overcome this problem?Don't try to write binary data as if it were text. (Write it as binary data)

Similar Messages

  • InsufficientMemoryException while sending large byte array in WCF Service callback

    Hi
    I have a datacontract with a large byte array that is passed by the WCF Service back to the client using a callback contract.
    Until the byte array size remains below 25-30 MB, it is passed OK, but as soon as it exceeds that, an InsufficientMemoryException is thrown on the service side. I have set the max message sizes at 100 MB and using MTOM Encoder.
    I am using WSDualHTTPBinding with sessions and message security - hence streaming is not an option. I know chunking channels are an option, but I want to try to tune the service and client to maximize the byte array size which can be sent over a normal channel.
    Kindly advise how to tune settings to get to around 100 MB byte array size.
    Binding section of web.config is given below. Same settings for sizes are used on client.
    Thanks
    Abhishek
     <wsDualHttpBinding>
            <binding name="WSHttpBinding_IService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
    transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="100000000" maxReceivedMessageSize="100000000" messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true">
              <readerQuotas maxArrayLength="100000000"  />
              <security mode="Message">
                <message clientCredentialType="Certificate" algorithmSuite="Default"  />
              </security>
            </binding>
          </wsDualHttpBinding>

    Hi abhisinghal21,
    >>InsufficientMemoryException while sending large byte array in WCF Service callback
    First please try to increase the timeout value in the both client and service side to see if it works:
    closeTimeout="00:10:00" openTimeout="00:10:00"
    receiveTimeout="00:10:00" sendTimeout="00:10:00"
    Then since you do not want to the use the Chunking option to help you, maybe you try to change the wsDualHttpBinding to use the binding which supports the streaming mode and supports callback.
    In streaming transfer mode, the receiver can begin to process the message before it is completely delivered. And the streaming mode is useful when the information that is passed is lengthy and can be processed serially. Streaming mode is also useful when the
    message is too large to be entirely buffered. So it will be better for you to use the streamed mode.
    For more information, please try to check:
    #How to: Enable Streaming:
    http://msdn.microsoft.com/en-us/library/ms789010(v=vs.110).aspx .
    Best Regards,
    Amy Peng
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to adjust a "control array" size

    I have a program that creates a digital PWM signal with variable duty cycle. The duty cycle changes every 50 ms, but the overall wave frequency stays at a frequency determined by the user. I have the VI attatched.
    My problem is this...I need to be able to control the overall cycle time. This means the size of my array of duty cycles needs to adjust based on the cycle time (i.e. a cycle time of 1 second would require 20 of the 50 ms slots, while a 1.3 second cycle would need 26).
    I currently have only 4 slots in my array, meaning the total cycle time is .2 s. I understand how to manually add and remove elements to the array, but I can't figure out how to add a control to it so that the array size changes automatically, allowing much quicker entry of data. As of now I can make it work, it just takes super long to add or delete array elements. The ideal situaton would have a constant control for cycle time divided by 50 that would change the array size.
    I can't find any info on this, and I think I even saw a post asking that this kind of feature be added. I'm relatively new to this program.
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    var_duty_cycle.vi ‏25 KB

    Currently, your VI is a one-shot deal. What you need is a state machine that updates the pct duty cycle array control as a function of the frequency while the current I/O code is idle.
    I would use an array of clusters, where each cluster contains e.g. a sequence number, a duty cycle, and a string as element label. Show the scrollbar and set the size whenever the relevant inputs change. Do you want to reset the current setting when the number changes or do you want to retain the current settings as much as possible? You could just use the existing values, reshape to the larger or smaller size, and write it back to the control via a local variable. Set all elements  except the percent to disabled so they act as indicators and cannot be changed by the user.
    (You also need to program around it if the operator tries to manually add more elements. A better solution would be this idea, so vote for it .)
    Some more general comments bout your code:
    Why do you use extended precision floating point. All your waits are internally just integers. EXT makes no sense
    There is a primitive for 1/x. However, you could just do a 1000/x and eliminate the multiplication afterwards. SInce you are dealing with integers, you can even do the division using quotient&remainder. Depending on the allowed frequency range there are possibly no orange data needed at all.
    Make the diagram constant representation match the rest of the code.
    The pulses/50ms indicator belongs before the loop. No need to recalculate and refresh it over and over from the same input values.
    LabVIEW Champion . Do more with less code and in less time .

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

  • Hex code string -- byte array

    hi everyone,
    i have a bunch of hexadecimal code which is read from a text file into a String.
    i want to put this String into a byte array without changing anything.
    my algorithm is like this -
    String strFromTextFile = "FFD8FFE0001";
    * put strFromTextFile into byteArr[ ]
    byteArr[0] == 'F';
    byteArr[1] == 'F';
    byteArr[2] == 'D';

    hi, i think this simple code will fulfill ur need
    public class hex {
         public static void main(String[] args) {
              String str= "AFFD8FFE0001";
              byte hexbytes[] =     hexstore(str);
    public     static byte[] hexstore(String str)
          int length = str.length();
          if((length%2)!=0)
               length++;
               str = new String(str+"0");
          byte[] a = new byte[length/2];
          for(int i=0,j=0;i<str.length();i=i+2,j++)
              byte c =(byte) str.charAt(i);     
              if(c<65)
                   c= (byte)((int)c-48);               
              else
                   c= (byte)(10+(int)c-65);
                   c=(byte)((int)c<<4);
              byte d =(byte) str.charAt(i+1);
              if(d<65)
                   d= (byte)((int)d-48);               
              else
                   d= (byte)(10+(int)d-65);
                   c = (byte)(c | d);
                   a[j]=c;
              for(int i=0;i<length/2;i++)
                   System.out.println("byte "+((int)a));
              return a;
    example ( for first 2 characters)
    AF has to be stored as 1010 1111
    1010 1111 is stoted in a[0];

  • MD5 - Size Of Digested Byte Array

    Hey There.
    After MD5 digesting and then Base64Encoding a string, I would end up with a byte array such as this:
    GH70Q2Ei0cwvQNwrkvDroA==
    It changes with the input, but is always 24 characters in length. I would have thought it to be 32 characters. Any reasons???
    I'm doing the UTF-8 thing. Refer to code in previous post where I'm looking for critique of code.
    Thanks,
    Vic

    I do think about what I'm doing. I know I have to
    encode digested value to get data into db. I'm not
    aware of HEX encoding, only BASE64.If you aware of Base64 and MD5, I suppose you know the digest size produced by MD5 and the fact that Base64 increases the size of encoded data to fixed percentage (which is less then 50%).

  • Changing a byte in a byte array???? HELP

    Hey I have the following code
         String plainString = new String();
         byte[] byt = new byte[0];
         byte change;
         try
              int length = (int)(keyf.length());
              byt = new byte[(length++)];
              keyf.readFully(byt);
              keyf.seek(0);
         }catch(IOException e){System.err.println(e);}And I want to edit the byt array at position (length--) and add the character "," there. Also changing the byt array at its current position to eof. Anyone know what to do???

    Make a new array with a size of length+1.byt = new byte[(length++)];
    keyf.readFully(byt);
    byte[] b2 = new byte[byt.length+1];
    System.arraycopy(byt, 0, b2, 0, byt.length);
    b2[b2.length - 1] = (byte)',';

  • How to read a large file(size around 100 kbytes) into a byte array in JAVA

    aa

    But I cannot use array subscript as a long value.what do you mean?
    are you rying the following:
    long aSize = 100000;
    byte[] array = new byte[aSize];
    if this is the case, then don't do it, for your 100k file int is far more than enough.
    but in case you jsut get error while:
    byte b = array[100000];
    then it's probably because you'r array is of size 100000, that means you have bytes from 0 to 99999 in there, and 100000 is one passed the end of the array.... jus in case make your array size to be 1234567 (far more than needed for your file) and see if you still get that exception, if not, then your array was too small. but if it fixes your prob, then don't leave it as it is, try to work out the right size for array and use that....
    i wouldn't recommend using static array size, since that file might some day be bigger than you expected, and then you'd have to recompile your program.
    HTH

  • Reducing size of Image or byte array

    Hello,
    I am making a program where i have to send user's screen to another PC,
    So I use class Robot to make a screen capture and send it via UDP.
    However this is still too slow, my question is: is there some library to compress the size of byte array or Image?
    Thanks for help,
    Juraj

    thanks for help i found it
    byte[] input = ...;
    // Create the compressor with highest level of compression
    Deflater compressor = new Deflater();
    compressor.setLevel(Deflater.BEST_COMPRESSION);
    // Give the compressor the data to compress
    compressor.setInput(input);
    compressor.finish();

  • Generated Webservice proxy: Maximimum size of byte array

    Hi,
    We have generated a webservice proxy with JDeveloper (version 10.1.3.4.0) from a WSDL supplied by a .Net webservice. One of the Webservice returns a byte array. We are facing a problem when the size of the returned byte array exceeds the limit of 5 MB. We have tried to increase the heap size of the OC4J but that did not solve the problem.
    Does anyone know if there is a maximum value limit which can be passed through a byte array? Is it configurable?
    A workaround would be flushing the byte array in chunks, but the webservice returns the byte array as a single returned value.
    Regards,
    Sjoerd

    Hi,
    The webservice was called by Oracle Forms. The problem was solved by Metalink Note 562561.1 - Webservice Fails To Run With java.lang.OutOfMemoryError.
    Regards,
    Sjoerd

  • Change quality of JPEG byte array

    I have a JPEG file which I read into a byte array in my program, the problem is that I need to change the quality of this image, is it possible? If so, how?

    i think these two links could help you:
    [JAI cookbook|http://www.lac.inpe.br/~rafael.santos/JIPCookbook/6040-howto-compressimages.jsp]
    [java.sun.com|http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Encode.doc.html#51423]

  • How to change the image into byte and byte array into image

    now i am developing one project. i want change the image into byte array and then byte array into image.

    FileInputStream is = new FileInputStream(file);
    byte[] result = IOUtils.toByteArray(is);
    with apache common IO lib

  • How to change array size in forms6i

    Does anyone know how to change the array size in Forms6i.
    The only runtime option i see is Array=YES (Use array SQL processing). But I want to increase the number of records per request retrieved. There's supposed to be a 'Query Array Size' parameter but I have no clue where to find this ...
    kind regards

    Kurt, it may sound an obvious point to make but - did you even consider the on the help??
    We spend a lot of effort in producing this and it should be the first stop for quesions.
    Bring up the help, click on index and then type in "QUERY ARRAY" - and the list automatically moved to the topic you want.
    Regards
    Grant Ronald
    Forms Product Management

  • Change array size and delete duplicate row

    Hello,
    I am running a program that does a for loop 3 times.  In each loop, data is collected for x and y points (10 in the example provided).  How can I output the array with the 30 points in a simple 2D array (size 2x30)?
    Also, from the array, how do I delete duplicate rows that contain the same x-value? 
    Thanks,
    hiNi.
    Solved!
    Go to Solution.
    Attachments:
    array size.vi ‏10 KB

    Hello,
    THANK YOU for solving my first issue!  Attached is the data set that contains the duplicate entries for the x-axis values.  The y-axis value may be different, but not the x.  I would like to delete the 2nd row that contains the same x-value.
    Here is simple example of my input and desired output:
    IN: 
    28.512000 -115.310532
    28.812000 -86.937660
    29.112000 -116.877052
    29.412000 -87.223625
    29.412000 -111.349045
    30.012000 -86.510780
    30.312000 -112.048187
    OUT:
    28.512000 -115.310532
    28.812000 -86.937660
    29.112000 -116.877052
    29.412000 -87.223625
    30.012000 -86.510780
    30.312000 -112.048187
    I am thinking of comparig the last x-axis value to the current one, and if it is the same, then not parse that row.  The attached VI is as far as I got.
    Any help will be greatly appreciated.
    Thanks,
    hiNi
    Attachments:
    delete duplicate row.vi ‏8 KB
    data.txt ‏1 KB

  • Maximum size of a byte array?

    Hi,
    I'm trying to read in a file into a byte array as following:
    byte[]inputformat = new byte[1280];
    FileInputStream in= new FileInputStream(file);
    BufferedInputStream buffer= new BufferedInputStream(in);
    int len = buffer.read(inputformat);
    The problem appears when I try to access the 1024th array-element (inputformat[1024]) afterwards. Is there a limitation in the byte-arrays, or prehaps in the buffer.read-method?
    All comments are welcomed!
    Cheers,
    Slafs

    I executed the following code:
    import java.io.*;
    public class BufferTest {
        public static void main(String[] args) {
            try {
                byte[] inputFormat = new byte[1280];
                File inFile = new File(args[0]);
                FileInputStream in = new FileInputStream(inFile);
                BufferedInputStream bis = new BufferedInputStream(in);
                int len = bis.read(inputFormat);
                System.out.println("Read " + len + " bytes");
            catch (IOException e) {
                System.out.println("Error: " + e.toString());
    }To produce the following output:
    $ java BufferTest snapshot1.png
    Read 1280 bytesSo, I am not sure where your problem lies, but I don't think it's in the code you posted.
    Good luck
    Lee

Maybe you are looking for

  • Artist List View in iTunes 11

    Is there a way to set "Artist List" view as the default view for all playlists? There has to be a default setting somewhere so that you don't have to go through every single playlist and manually change it, right? Thanks!

  • How to create an Input Ready Query in Bex Excel with no transact data

    Hi We created a query where we want the user to put in NEW LINES. This query has in general no data when user starts planning. We have 2 front-ends for this, Bex Web and Excel. Both shows initial 'no data available BexWeb': Implementing the command s

  • Can't access 2d Hard Drive

    Am running Windows 7 Home Premium 64 bit. System has worked fine for over a year. All of a sudden, I cannot access files on my 2d HDD (WD 1TB).  Checked drive thru My Computer. Drive appears as NTFS Drive and shows 0 bytes for size. Am unable to acce

  • The awesome bar is suggesting history

    I changed my settings so that the awesome bar only suggests my bookmarks. However, it still is suggesting history (and items that are not in my bookmarks). I've deleted my history multiple times, but websites that I have only visited once are being a

  • Asset Balances not tally to GL Balances with small difference .1 paisa

    Hi Guru, Asset balance report- s_alr_87011964 not tally to GL balance- FBL3N with a small difference .1 paisa,Please sombody can help me solve this issue. Advance thanks. Thanks, ND