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 8162067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:37:48+00:00 2026-06-06T18:37:48+00:00

I am developping an Android app, and I need to use java Signature class

  • 0

I am developping an Android app, and I need to use java Signature class for data authentication.

On each Android device, I can sign data and verify its signature. However, given a definite chunk of data to sign, a definite modulus, a definite private exponent and a definite public exponent, the outputs of my signatures are different, depending on devices. I did try with bunch of devices, and I obtain the same signatures for Android 3.2 and 3.2.1, but a differents for an Android 2.2.x device.

I compute these signature from constant fields that I generated previously using a KeyFactory with RSA in a java project. The keysize is 2048bit.

Here is a quote of the code that I use to invoque Signature and Verification.

public byte[] signData(byte[] data, PrivateKey privateKey) throws ... {
        Signature signature = Signature.getInstance("SHA256withRSA");
        signature.initSign(privateKey);
        signature.update(data);
        return signature.sign();
}

public boolean verifyData(byte[] data, byte[] sigBytes, PublicKey publicKey) throws ... {
        Signature signature = Signature.getInstance("SHA256withRSA");
        signature.initVerify(publicKey);
        signature.update(data);
        return signature.verify(sigBytes);
}

If I am not mistaking, the signature using SHA256 with RSA is deterministic. Then how can I explain such a behaviour? Another interesting question, how could I make that work cross-devices, i.e. the signatures would be same, no mather which device I use?

Thank you in advance, Franck!

  • 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-06T18:37:49+00:00Added an answer on June 6, 2026 at 6:37 pm

    Yes, SHA256withRSA is completely deterministic.

    In theory you could be affected by a bug (see an example) in an old modified BouncyCastle library version found on one of the Android versions. Such a bug might be eliminated if you used SHA512withRSA instead, well, at least the referenced one would be.

    However, before you start digging into the hash algorithm, check close to home.

    Maybe you have obtained your byte array through a call to String.getBytes. This call depends on the default platform encoding which is different between Android 2.2 and Android 2.3. This implies that while your strings are the same in both cases, the byte arrays might not be.

    To get encoding under control, and make your code platform independent, specify encoding as a parameter:

    plainText.getBytes("UTF-8")
    

    Failing this, there are a few more tactics to get a platform independent implementation.

    • wait until 2.2 with the presumably buggy library dies out
    • distribute a known good library (jar) with your software. If that would be BouncyCastle, you will have problems making sure that your and not Android’s classes are loaded. The solution is called SpongyCastle.
    • play with alignment/padding. Try to make the message length in bytes to be congruent with 0,55, 56 or 63 modulo 64 by adding your own fixed padding and hope that one of these options will start giving portable signatures. These values are chosen to interact with the outermost part of the suspect algorithm which is padding to 512 bit blocks.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developping an Android app, and I need to encode and decode a
I am developing an app for android where I need some data from a
I'm developping my first Android App. I need to execute a command in a
I am developing an android app. I need to call my MainActivity without reloading
I'm developing an android app, and I need to have a json response of
I'm developing an app in Android and I need to traverse a xml file.
i am developping and android app in spanish and english languages Its possible to
I am about to start developing an android app and need to get an
I'm developing android app. It's some sort of social network. Where user can add
I am developing an android app in which i need to display images after

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.