aspose file tools*
The moose likes Java in General and the fly likes Problem in Using Key coming from C# Code in Jav For DES Decryption Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem in Using Key coming from C# Code in Jav For DES Decryption" Watch "Problem in Using Key coming from C# Code in Jav For DES Decryption" New topic
Author

Problem in Using Key coming from C# Code in Jav For DES Decryption

Tarun Khandelwal
Greenhorn

Joined: Feb 23, 2012
Posts: 19
Hello Everyone,

I have to use DES Encryption.
But the Key is coming from C# code. And that is having double Bytes Character.
So when i am using that Key in my code, i am getting Key Length more than what i need.
Eg. Key coming from C# code :- zkouškaa, Which returns me Bytes :- 122, 107, 111, 117, -59, -95, 107, 97, 97.
Since in C# it takes the bytes as unsigned , there String is returning only 8 bytes that can be used to construct key. But With Java its returning 9 Bytes , which is making the Problem.

Can anyone please help me with the Issue.

I have one more thing.
The Key coming is in Hexa Format, so is there any way that i can directly use Hex String as Key?
Would that be better or Possible?.

Thanks,
Tarun Khandelwal
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

I might be mistaken, but I believe C# encodes the String to bytes in an encoding different from Java. If you use an encoding that can represent all the characters (eg. Unicode) on both platforms, I believe you'll get the same bytes out. Java's String class has several overloaded getBytes() methods, some of which allow you to specify the encoding (charset). I don't know how to do that in C#, though.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Using Key coming from C# Code in Jav For DES Decryption