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

  • Home
  • SEARCH
  • 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 6847549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:45:29+00:00 2026-05-27T00:45:29+00:00

Here is the flow of my Android code: I am using SHA-1 hashing to

  • 0

Here is the flow of my Android code:

I am using SHA-1 hashing to hash a password entered by the user via EditText. I get a hash string as output over here.

After that I am calling a SOAP web service (created using .NET framework) that performs the same SHA-1 hashing using ASCII encoding and returns me another hash string.

Now since the input string is same in both the cases, my hash strings are same as expected.
See logcat below. But when I am comparing the hash strings, I am not getting the result as expected

Here is my Android code followed by logcat:

           package com.kar.encodePassword;
           import java.io.IOException;
           import java.io.UnsupportedEncodingException;
           import java.net.SocketException;
           import java.security.MessageDigest;
           import java.security.NoSuchAlgorithmException;
           import org.ksoap2.SoapEnvelope;
           import org.ksoap2.serialization.SoapObject;
           import org.ksoap2.serialization.SoapPrimitive;
           import org.ksoap2.serialization.SoapSerializationEnvelope;
           import org.ksoap2.transport.HttpTransportSE;
           import org.xmlpull.v1.XmlPullParserException;
           import android.app.Activity;
           import android.os.Bundle;
           import android.util.Base64;
           import android.util.Log;
           import android.view.View;
           import android.widget.Button;
           import android.widget.EditText;
           import android.widget.Toast;

   public class PaswordencodingActivity extends Activity {
       /** Called when the activity is first created. */

 private static final String soap_action = "http://tempuri.org/HashCode";
 private static final String method_name = "HashCode";
 private static final String namespace2 = "http://tempuri.org/";
 private static final String url2 = "http://10.0.2.2/checkhash/Service1.asmx"; 

String password="abc";
public final static int NO_OPTIONS = 0;
String hash;
    String result2;


@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final EditText pass=(EditText)findViewById(R.id.editText1);
    Button encode=(Button)findViewById(R.id.button1);            
    encode.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v)  {
            // Perform action on click
            password=pass.getText().toString();
            if(password!=null){
                try { 
        SHA1(password) ;
        } catch (UnsupportedEncodingException e) {                                          
                      e.printStackTrace();
        } catch (IOException e) {   
            e.printStackTrace();                    
                      }
            }
            else{
       Toast.makeText(PaswordencodingActivity.this, "this is a negative onClick", Toast.LENGTH_LONG).show();
            }

           }

          });


        }


private static String convertToHex(byte[] data) throws java.io.IOException 
 {
        System.out.println("data received is"  +data);

        StringBuffer sb = new StringBuffer();
        String hex=null;

        hex=Base64.encodeToString(data, 0, data.length, NO_OPTIONS);

        for (int i = 0; i < data.length; i++) 
        {            
            if (hex.length() == 1) 
            {
                sb.append('0');
            }
            sb.append(hex);
        }

       return sb.toString();
    }

public void SHA1(String text) throws IOException
{
    MessageDigest mdSha1 = null;
    try 
    {
      mdSha1 = MessageDigest.getInstance("SHA-1");
    } catch (NoSuchAlgorithmException e1) {
      Log.e("myapp", "Error initializing SHA1 message digest");
    }
    mdSha1.update(text.getBytes("iso-8859-1"), 0, text.length());
    byte[] data = mdSha1.digest();
    hash=convertToHex(data);

    System.out.println("data going is"  +data);
    System.out.println("hash value"+hash);

    try
    {
        result2=call3(password);
        if(result2.equalsIgnoreCase(hash.toString()))
        System.out.println("success");


    } catch (XmlPullParserException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   

        }

public String call3(String pass) throws XmlPullParserException
{
        String b=""; 

        SoapObject request = new SoapObject(namespace2, method_name);      
        request.addProperty("str",pass);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
        envelope.dotNet = true; 
        envelope.setOutputSoapObject(request);

        HttpTransportSE  android = new HttpTransportSE(url2);

        android.debug = true; 
 try 
 {

        android.call(soap_action, envelope);

        SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
        Log.i("myapp",result.toString());
        System.out.println(" --- response ---- " + result); 
        b=result.toString();


        } catch (SocketException ex) { 
            ex.printStackTrace(); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 

        return b;   

}
}

Basically when I am trying to compare the two hash strings I am not getting the result

Why so ? can anyone help?

Logcat:

        11-25 17:09:50.899: INFO/System.out(275): data received is[B@44ef8eb0
        11-25 17:09:50.909: INFO/System.out(275): data going is[B@44ef8eb0
        11-25 17:09:50.909: INFO/System.out(275): hash valueUGGpBypVug3K+/4xONpqv9wkFd8=
        11-25 17:09:50.909: INFO/System.out(275): UGGpBypVug3K+/4xONpqv9wkFd8=
        11-25 17:09:50.909: INFO/System.out(275): UGGpBypVug3K+/4xONpqv9wkFd8=
        11-25 17:09:50.909: INFO/System.out(275): UGGpBypVug3K+/4xONpqv9wkFd8=
        11-25 17:09:50.909: INFO/System.out(275): UGGpBypVug3K+/4xONpqv9wkFd8=
        11-25 17:09:50.909: INFO/System.out(275): UGGpBypVug3K+/4xONpqv9wkFd8=
        11-25 17:09:50.909: INFO/System.out(275): UGGpBypVug3K+/4xONpqv9wkFd8=
        11-25 17:09:50.909: INFO/System.out(275): UGGpBypVug3K+/4xONpqv9wkFd8=
        11-25 17:10:01.730: INFO/myapp(275): UGGpBypVug3K+/4xONpqv9wkFd8=
        11-25 17:10:01.730: INFO/System.out(275):  --- response ---- UGGpBypVug3K+/4xONpqv9wkFd8=
  • 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-05-27T00:45:30+00:00Added an answer on May 27, 2026 at 12:45 am

    Try

    result2 = result2.trim();
    hash = hash.trim();
    
    System.out.println("result2='" + result2 + "'");
    System.out.println("hash ='" + hash + "'");
    
    if(result2.equalsIgnoreCase(hash))
       System.out.println("success");
    

    If this does not help, check the actual arrays:

    byte[] a = result.toString().getBytes() 
    byte[] b = hash..getBytes();
    

    If the arrays are not equal, you have strings in different encodings.

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

Sidebar

Related Questions

Here's the flow I'm looking for for authentication: Attempt to pull in the user's
i try to get the name of contact using number in 2.3.4 android, but
Here's the flow that I am trying to achieve: 1) User uploads an audio
In the authentication flow documentation here it mentions the CODE which is returned upon
We're using git flow. Here is the flow. git flow feature start myfeat git
Let's take a simple "Account Registration" example, here is the flow: User visit the
There is an interesting post over here about this, in relation to cross-application flow
Here is my code, which takes two version identifiers in the form 1, 5,
I have an android activity and a service implemented using aidl. Works like a
Here is a flow that I can not figure out how to work. (

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.