Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using c# code to compute the checksum.

I am using crc32 dll.

i need to send the checksum value to another application, they are using JAVA.

they are also using the same crc32 algorithem.

My c# code below.

<pre>  Crc32 achk = new Crc32();

byte[] bytes = System.Text.Encoding.UTF8.GetBytes("6210|25042017164248|Srikanth|123456|R|123456789|123456789|100|test|10|srikanth|8019412555|||Srikanth");
achk.Update(bytes);


My value is: 4140400987

from their end, the value is:355590133

please suggest the code which is both compatible for c# and java.




What I have tried:

check sum logic compatible for c# and java.
Posted
Updated 25-Apr-17 2:05am
Comments
Tomas Takac 25-Apr-17 7:46am    
Perhaps they are using different seed.
Member 13150761 25-Apr-17 8:39am    
They are using the same seed.
Richard Deeming 25-Apr-17 15:38pm    
Perhaps they're using a different encoding?

1 solution

CRC's are based on polynomial values which may be different (see also Cyclic redundancy check - Wikipedia[^]).

So you have to use the same polynomial values with the same bit order for your C# and Java calculations.

The Java sources can be found here: Source for java.util.zip.CRC32 (GNU Classpath 0.95 Documentation)[^]. It is based on RFC 1952[^]. According to those the polynoimal 0xedb88320 is used.

So you have to ensure that the C# calculation uses the same. Check the documentation of the used DLL (or the source code if available). If the polynomial can't be specified you have to use a different DLL or write your own (e.g. by converting the Java code to C#).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900