Byte (Java) and byte (DotNet) interoperability

Hi!
I have the following problem. In DotNet platform I am encrypting using RijndaelManaged, from System.Security.Cryptography, which uses AES encryption method. In Java platform I use the javax.crypto.Cipher, in order to decrypt the message (in byte[] array) encrypted in DotNet platform. The problem is that in DotNet there isn´t an AES encryption that uses bytes from -128 to 127. The DotNet´s RijndaelManaged uses the byte type. In that platform, the byte type can have values from 0 to 255. I have already tried to convert byte to sbyte (signed byte), trying to make it equivalent to the byte type from Java, but when the message arrives in the Java platform the javax.crypto.BadPaddingException is thrown, with the message "Given final block not properly padded".
How can I solve the problem?
Thanks!

Here are the steps ...
1. Generate client-side artifacts from the WSDL exposed by C# web service using "wscompile -gen:client"
2. Write a client and then invoke the web service (Refer to http://java.sun.com/webservices/docs/1.3/tutorial/doc/JAXRPC5.html#wp79965 for more details)
Thanks for your interest in JAX-RPC.
Regards,
-Arun

Similar Messages

  • [svn:osmf:] 11205: Fix bug FM-169: Trait support for data transfer sample doesn' t display bytes loaded and bytes total for SWF element

    Revision: 11205
    Author:   [email protected]
    Date:     2009-10-27 15:04:26 -0700 (Tue, 27 Oct 2009)
    Log Message:
    Fix bug FM-169: Trait support for data transfer sample doesn't display bytes loaded and bytes total for SWF element
    Ticket Links:
        http://bugs.adobe.com/jira/browse/FM-169
    Modified Paths:
        osmf/trunk/apps/samples/framework/PluginSample/src/PluginSample.mxml
        osmf/trunk/apps/samples/framework/PluginSample/src/org/osmf/model/Model.as

    The bug is known, and a patch has been submitted: https://bugs.freedesktop.org/show_bug.cgi?id=80151. There's been no update since friday, so I wonder what the current status is, or if it's up for review at all.
    Does anyone know how we can be notified when this patch hits the kernel?

  • String.getBytes() & String(byte[]) - java.nio.BufferOverflowException

    The application in question uses JNI for legacy integration and I suspect the legacy code is corrupting the stack causing the above error. However, the error does not occur in Java 1.3, only Java 1.4.
    Is there some way to suppress 1.4's use of the native IO API when encoding and decoding byte streams? This would at least provide a workaround in the meantime.
    Thanks.

    This is beginning to make a little sense. The problem is that you got a String and you don't want one. A String wraps an array of chars, which your app needs, right? Specifically they're chars because you need 16-bit char sets.
    Presumably the getBytes() method call is used to get an array of bytes for some data transfer operation. java.nio was probably added in 1.4 as it has some very efficient ways of handling buffers as simultaneously of two or more types. It's trying to use the underlying char array as a byte array and there's a straight up bug someplace.
    Workaround is strange to contemplate, but I'm pretty sure it will work: use String.getChars() to get an array of chars, and then use java.nio yourself to create your byte array! If you've never been there, it's not very hard. I use nio all the time and it's never been a problem.

  • Should I save memory by using byte, short and float?

    Our teacher tells us always to use int and double. But what if I don't need such precision or large values?
    Shouldn't I use byte, short and float instead?

    You don't save any memory if you use floats instead of doubles in a method. These variables only exist on the stack when the method is executing. Also remember that Java may do type conversions from float to double in expressions. This may make your code slower.
    If you have a class with large quantities of doubles, for example an array of 100000 doubles, then you may consider using floats, because the memory saving is substantial. If you access the array from outside the class via double methods you can easily do this change local to the class late in the development process.
    I'd say generally it's better to do as your teacher says and standardize on doubles and integers. If you write your program well you can always optimize later if you have to.

  • When to use short and byte

    when do i should really use byte and short anyway?
    let's say i'm writing a MIDlet and i really really want to save up some memory at run time, would it be helpful if i will use short and byte if i dont need large numbers? let's say i only need a maximum representation of 500?
    i know int is commonly used, but is it worth the change?

    I don't know about the Micro Editon VM, but the Java Standard Edition run-time VM has no special instructions for operating using byte primitives as opposed to, say, integer or short primitives, and byte primitives in the VM are stored as ints, I believe. So, chances are your optimizations of these primitives aren't going to save you that much in terms of speed or memory. However, again, my previous comments only apply to the Standard Edition VM [feel free to correct them if I am wrong, as I am not sure if these restrictions have changed since Java v1.3 or not].
    Plus, if your value is going to be a maximum of 500, you need a short because the signed byte primitive will only be valid across the -128 to 127 range.
    -Dok

  • Bits and Bytes

    Hello,
    As much as I know Java can only stream bytes and cannot save a single bit to a file. However is there any place where this is actually documented? and am I right to state this?
    Thanks and Regards,
    Sim085

    Manfolium2 wrote:
    Single bits or even bytes are impractical because of addressing. ( since you have to store the addresses somewhere on the drive, too ) If you save a one bit file you still use the the whole address bin. It's like you rent a huge P.O. box and fill it with one letter. You still have the whole box reserved for you. Most drive formatters will allocate 4Mb to one address. This is common in all computing devices and all laguages. But, if you are referring to the java bytecode,yes when you compile a .java file it becomes encoded in an intermediate code (bytecode) like C#. This way it can run on any machine that has the Java Runtime Environment since it will be compiled into machine code (binary) when it is run by the Java Virtual Machine. This is the foundation of Java and distributed programming. So, yes it is very documented. I'm not sure if this helps. If you want to know more about bytecode and its advantages/disadvantages go to: [http://java.sun.com/docs/white/langenv/Security.doc3.html]
    I like that post-box analogy. Thanx for the fish.
    Most drive formatters will allocate 4Mb to one address.Ummm... 4meg sounds big ???? I thought the block size was 1k on most modern IDE drives.

  • Object to byte [] and byte [] to Object

    Hi,
    I am quite new to java and need some help. My question is how can I convert an Object to byte [] and convert back from byte [] to Object.
    I was thinking of something like:
    From object to byte []
    byte [] object_byte=object.toString().getBytes();
    When I try to do:
    String obj_string=object_byte.toString();
    But obj_string is not even equal to object.toString().
    Any suggestions?
    Thanks

    // byte[] to Object
    byte[] b = new byte[]{1};
    Object o = (new ObjectInputStream(new ByteArrayInputStream(b))).readObject();
    // Object to byte[]
    Object o = new Object();
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();    
    ObjectOutputStream objStream = new ObjectOutputStream(byteStream);       
    objStream.writeObject(o);  
    byte[] b = byteStream.toByteArray();

  • About audio format encoding and byte[] data

    1.may i know how many types of encoding besides 5 types list in java api?
    2.how will encodings affect output sound?
    3.i get an exception when i try to to convert from PCM_UNSIGNED to ALAM. Is there any plugin to support it?
    java.lang.IllegalArgumentException: Unsupported conversion: ALAW 22050.0 Hz, 8 bit, mono, 1 bytes/frame, from PCM_UNSIGNED 22050.0 Hz, 8 bit, mono, 1 bytes/frame.4.how will the number of channel affect output sound?
    5.how will the data array size affect output sound? what value should we put instead of 4096?
    byte[]     data = new byte[4096];
    while ((bRead = ais.read(data, 0, data.length)) != -1) line.write(data, 0, bRead);thanks for your reply~

    user13556330 wrote:
    1.may i know how many types of encoding besides 5 types list in java api?Too many to list...
    2.how will encodings affect output sound? They'll generally decrease the quality of the sound, or have no effect on the sound. Depends on the encoding...
    3.i get an exception when i try to to convert from PCM_UNSIGNED to ALAM. Is there any plugin to support it?
    java.lang.IllegalArgumentException: Unsupported conversion: ALAW 22050.0 Hz, 8 bit, mono, 1 bytes/frame, from PCM_UNSIGNED 22050.0 Hz, 8 bit, mono, 1 bytes/frame.
    There's no ALAW converted built-in, no. There probably is a plugin you can find on the internet to do the conversion, but, it's up to you to find it...
    4.how will the number of channel affect output sound?Generally sound is designed to be rendered as one-channel per speaker... so "stereo" is 2-speakers, "surround sound" is 5 or 7 speakers, etc... you don't have to follow this rule, but, that's the "goal" of multi-channel sound.
    5.how will the data array size affect output sound? what value should we put instead of 4096?Assuming you're doing that code to play a file, that's essentially your "buffer" size. If you use a buffer that's too big, it'll take a long time to begin playing... if you use a buffer that's too small, it'll have too much overhead and your audio may skip.
    The standard sound format is 2-channel 16-bit PCM played at 44.1K, so a buffer size of 4096 represents about 25 milliseconds of sound... which is a good length for a buffer. I'd recommend keeping your buffer length to where it represents 20-50 milliseconds worth of data...but you can always have a longer buffer. Standard anti-skip CDs generally use a 4-second buffer, which would be 705,600 bytes...

  • Help !! Bits and Bytes - Come get these Dukes

    Can someone please shed some light on this ... I come from a C background and had no problems reading files in bits. I can't seem to find a way to read bit by bit in Java.
    I have a file which is written in an unknown format. All I have been told is that it could be either 4 / 5 / 6 etc bits per byte.
    I want to write a program that can create the above byte sizes and then print the ascii equivilent.
    So any help or an example on how to read a file bit by bit would be most appreciated.
    Robin

    I come from a C background and had no problems reading files in bitsInteresting!
    I can't seem to find a way to read bit by bit in Java.That's because there isn't any bit reader in Java but there is nothing to stop you from reading a byte at a time and pick the bits you want..... It seems to me you're not going to get very far without having more info on what's in the file. BigEndian/LittleEndian could compound your problem.
    Have fun!
    ;o)
    V.V.

  • How to pass Java signed byte into VB6 unsigned program

    Hello everyone
    I need to build a client in Java to talk to a VB6 server. I am the point to pass the encrypt username and password into the server. The VB6 code for the encryption is
    Crypt = Crypt & Chr(Asc(Mid$(Text, Len(Text) - X + 1, 1)) Xor &HA3)
    My Java code is
    cryptOutput = cryptOutput + ((char)(((int) input.charAt(i)) ^ ((byte)0xa3)));
    The server doesn't seem to understand my username and password. I highly suspect the reason being that Java byte is signed and VB6 is unsigned.
    How could I overcome this problem? I did some research and things like &0xFF didnt help...
    Thank you in advance!

    A bit more information about my problem
    The server uses Crypt function to encode or decode all the strings sent or received
    Public Function Crypt(ByVal Text As String) As String
        Dim X As Integer
        For X = 1 To Len(Text)
            Crypt = Crypt & Chr(Asc(Mid$(Text, Len(Text) - X + 1, 1)) Xor &HA2)
        Next X
    End FunctionIf you run Crypt(Crypt("0123")), you should get "0123" in return
    What I need to to make the same encode/decode function on my client side to be exactly the same as the server side. My java code for it is
    public static String crypt(String input)
            int i = 0;
            int len = input.length();
            int a2 = 0xa2; // variable used in original VB code for encoding
            String cryptOutput = new String("");
            for (i = 0; i < input.length(); i++)
                cryptOutput = cryptOutput + ((char)(((byte)input.charAt(len-i-1)) ^  ((byte)a5)));
            return cryptOutput;
        }My java crypt(crypt("0123")) can also return "0123", but the result between crypt("0123") and Crypt("0123") is different. Maybe thats why the server can't authenticate the password I send it. (I use Java Socket class, while the server uses Winsock).
    I can already pass un-encrypt data (i.e string like "hello") successfully between the client and the server. But with encrypt data, I have no success :(
    I really think it's because of the byte differences between Java and VB6. Please point out my error :)
    Thank you for your time!

  • J2me Mobile client calling method which return byte[] java.rmi.MarshalExcep

    J2me Mobile client calling method which return byte[]
    java.rmi.MarshalException: Expected Byte, received: SGVsbG8gV29ybGQ=
    WebService1_Stub ws=new WebService1_Stub();
    try {
    String s=ws.getStringHelloWorld();// works fine
    byte s[]=ws.helloWorld(); // error java.rmi.MarshalException: Expected Byte, received: SGVsbG8gV29ybGQ=
    }catch(Expception e){
    ex.printStackTrace();
    }This same ws working fine in java standalone application please guide me what can be a problem ??
    Regards
    Haroon Idrees

    clear your app. server logs ( or make copies of them if will you need them) and redo the whole process. check out the logs and you should see some reason for this. i do not know if Borland's logs will turn out helpful, but it did help me out in certain other situations.

  • Unsigned byte: Java byte data type (0-255)?

    I need an "unsigned" byte type.
    How can I implement a one byte data type with values from 0-255 in Java?

    No there isn't an unigned byte, but you don't need
    one. You just separate storage representation from
    calculation representation. When you store the
    "unsigned byte" you use a signed byte. When you make
    calculations on the "unsigned byte" you use an
    integer. For this you need two conversion functions,
    public static int toInt(byte b) {
    return b + 128;
    public static byte toByte(int i) {
    return (byte)(i - 128);
    }These amazing functions must be tested off course.
    public void testUnsigned(int unsgn) {
    byte bA[] = new byte[1];
    int i = unsgn;          // 0 to 255
    bA[0] = toByte(i);    // stored as -128 to 127
    int j = toInt(bA[0]); // 0 to 255
    if (i==j)
    System.out.println("Yes it works!");
    Sorry, but your code doesn't work. I also tried the byte & 0xFF and I get strange results too. 0xFF transfer to 129, which (I think, but maybe I'm wrong) should transfer to 255 (0xFF == 1111 1111, no?). After some tests, I found that "ounos" solution is the best fitted (byte < 0 ? b+256 : b)
    If you only do a (byte + 128), you'll get, for example:
    0000 0000 (should be 0) == 128
    I think that only 1 case is enough to proove that this code doesn't work... :-)

  • FIle Creation in the Application Server With Unicode-8 and Byte-Order Mark

    Hi Guys,
    I've requirement of creating a file in the Application server with the Data.
    The Data Format Should be in UTF-8 and Byte-Order Mark.
    I need to supply this data from SAP to PRMS.
    I'm able to create a file with Unicode, but any of the guys have worked on Umicode with Byte-Order Mark, please let me know.
    Thanks,
    Adi.

    Hi Mathieu,
    If you haven't found an aswer yet, you can check in transaction SE24 CL_ABAP_FILE_UTILITIES method CREATE_UTF8_FILE_WITH_BOM. You can check the code of the method (it's very short) so you can understand how it works. It's also a static method so you can call it directly in your program.
    Ex:
    CALL METHOD cl_abap_file_utilities=>create_utf8_file_with_bom(your_file_name).
    I hope this helps.
    Pax Vobiscum.
    ~ Eric

  • SJIS- Japan Encoding Issues(*Unable to handle Double Byte Numeric and Spec)

    Hi All,
    Problem:
    Unable to handle Double Byte Numeric and Special Characters(Hypen)
    The input
    区中央京勝乞田1944-2
    Output
    区中央京勝乞田1944?2
    We have a write service created based on the JCA (Write File Adapter) with the native schema defined with SJIS Encoding as below.
    *<?xml version="1.0" encoding="SJIS"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd" xmlns:tns="http://nike.com/***/***********"
         targetNamespace="http://nike.com/***/*************"
         elementFormDefault="unqualified" attributeFormDefault="unqualified"
         nxsd:version="NXSD" nxsd:stream="chars" nxsd:encoding="SJIS">*
    Do anyone have similar issue? How can we handle the double byte characters while using SJIS encoding? At the least how can we handle double byte hyphen ??
    Thanks in Advance

    Have modified my schema as shown below and it worked well for me and i am partially successful up to some extent. Yet, not sure the workaround will resolve the issue at the final loading...
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd" xmlns:tns="http://nike.com/***/***********"
    targetNamespace="http://nike.com/***/*************"
    elementFormDefault="unqualified" attributeFormDefault="unqualified"
    nxsd:version="NXSD" nxsd:stream="chars" nxsd:encoding="UTF-16">*
    If anyone has the resolution or have these kind of issues let me know.........

  • Question on FileWriter and byte requestBytes[]

    if I have string Content, I can use the following code to write them to csv file
    byte requestBytes[] = Content.getBytes();
    ByteArrayInputStream bis = new ByteArrayInputStream(requestBytes);
    res.reset();
    res.setContentType("application/text");
    res.setHeader("Content-disposition","attachment; filename=" +"temp.csv");
    byte[] buf = new byte[1024];
    int len;
    while ((len = bis.read(buf)) > 0){
    res.getOutputStream().write(buf, 0, len);
    bis.close();
    res.getOutputStream().flush();bu tif I don't want to use string to collact data , I wan to use FileWriter fw = new FileWriter(filename);
    fw.append("Employee Code"); what can I do? in order to write them into a download able file ?
    thnak you!

    HJava wrote:
    if I have string Content, I can use the following code to write them to csv file
    byte requestBytes[] = Content.getBytes();
    res.reset();
    res.setContentType("application/text");
    res.setHeader("Content-disposition","attachment; filename=" +"temp.csv");
    res.getOutputStream().write(requestBytes);
    res.getOutputStream().close();
    Done. Dusted. Finished. You don't need all that other rubbish.
    but if I don't want to use string to collact data,What string?
    I wan to use FileWriter fw = new FileWriter(filename);
    fw.append("Employee Code"); what can I do? in order to write them into a download able file ?Don't use a FileWriter. Use a FileOutputStream 'fos' and call fos.write(requestBytes).

Maybe you are looking for