Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8033999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:52:47+00:00 2026-06-05T01:52:47+00:00

I have a C# WebService and a (Java) Android Application. Is there a SIMPLE

  • 0

I have a C# WebService and a (Java) Android Application. Is there a SIMPLE hash function that produces the same result between these two languages? The simplest C# hash is a String.GetHashCode(), but I can’t replicate it in Java. The simplest Java hash is not simple at all. And I don’t know if I can replicate it exactly in C#.

In case it’s relevant, I’m hashing passwords before sending it across the internet. I’m currently using Encode64, but that’s obviously not secure since we can reverse it.


EDIT: Ok, I settled on using SHA256. Incase somebody else needs a quick solution, here are the code that I used, considering that I wanted both the C# and the Java to output the exact same string and I needed the simplest possible solution.

Java

public String Hash(String s)
{
    StringBuffer sb = new StringBuffer();
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(s.getBytes());
        byte byteData[] = md.digest();
        for (int i = 0; i < byteData.length; i++) {
            sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16)
                    .substring(1));
        }
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return sb.toString();
}

C#

public static string Hash(String s)
{
    HashAlgorithm Hasher = new SHA256CryptoServiceProvider();
    byte[] strBytes = Encoding.UTF8.GetBytes(s);
    byte[] strHash = Hasher.ComputeHash(strBytes);
    return BitConverter.ToString(strHash).Replace("-","").ToLowerInvariant().Trim();
}

Thanks guys! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:52:48+00:00Added an answer on June 5, 2026 at 1:52 am

    First, the kind of hashes implemented by String.GetHashCode() and String.hashCode() are not designed to be used for this kind of thing. For a start, they only hash to a 32 but number (at least in the Java case), so there is a significant risk of collisions. In this case, if two different passwords map to the same hash … then someone has a chance of 1 in 2^32 that a randomly chosen password will be accepted. (And the flip side is that if the bad guy can intercept the 32 bit hash for a valid password, they have a big “leg up” in guessing what the original password was!)

    Second, sending a crypto hash (such as produced by MD5, SHA-256, etc), is probably not going to solve your security problems … unless you send the hash over SSL or something. Sure, the bad guy won’t be able to recover the original password was, but they CAN intercept and use the hash in a “replay” attack. (There are ways to combat this, but they either require a shared secret key, or use of public/private key encryption … and you HAVE TO know what you are doing if you want this to be secure.)

    In short, you need to discuss your whole problem and proposed solution(s) with someone who has solid security expertise.


    If you really think that this is not a security issue, then an MD5 hash should be fine. But don’t say that you weren’t warned …

    (But don’t use a simple 32-bit hashcode because that is barely more secure than base64.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one application in flex that is accessing the Java webservice using
I have a android webservice client application. I am trying to use the java
I have to access a existing SOAP webservice from an Android application. I have
I have an Android application that displays a list of names using checkboxes. I
I am trying to make an Android/ Java application that needs to connect to
I have a webservice in java that receives a list of information to be
I am accessing .NET webservice methods from my Android application using Java SOAP jar.
I have a java webservice, that must return a response if the login is
I have a legacy Java webservice based on Axis2. This webservice classes consist of:
I have an ASP.NET Webform which currently calls a Java WebService. The ASP.NET Webform

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.