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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:18:12+00:00 2026-06-10T09:18:12+00:00

I found 2 similar questions and tried to run the code given as solution

  • 0

I found 2 similar questions and tried to run the code given as solution as those said answers are not working out for me so raising the question with snippet of code.

  1. signature.verify() Always returns False
  2. Signature.verify() is always returning false

Both’s said answer is not working so please DONT treat this question as DUPLICATE

here is my code.

import com.sun.org.apache.xml.internal.security.utils.Base64;
import java.io.FileInputStream;
import java.security.PublicKey;
import java.security.Signature;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import xmlread.ReadXMLFile;


public class CertificateTest {


    public static void main(String[] sdd)  {

        try{
        FileInputStream fin = new FileInputStream("pub.arm");
        CertificateFactory f = CertificateFactory.getInstance("X.509");
        X509Certificate certificate = (X509Certificate) f.generateCertificate(fin);
        PublicKey pk = certificate.getPublicKey();
        byte[] sign = "Qn/rlJRdZAdlPpu1UmmjE+rup8rv8d6XlS9MngAorzYDXefw0vWEP4eHil3YHoA1JUkoQQOgmw0w0QZFmrQbS33sa2t76iuqXI7EtnAPU798K+hEXP88tsYDWJNJFo9DdhkGltP5dQ02DN030Q1w58aTF+yZFfY1KVOPx2bIoL8=".getBytes();

        Signature sig = Signature.getInstance("SHA1withRSA");
        sig.initVerify(pk);
        sig.update(Base64.decode(ReadXMLFile.getString().getBytes()));

        boolean verifies = sig.verify(Base64.decode(ReadXMLFile.getString().getBytes()));

        System.out.println("signature verifies: " + verifies);

        }catch(Exception ex){}
    }
}
  • 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-10T09:18:13+00:00Added an answer on June 10, 2026 at 9:18 am

    Below is the explanation before I knew that ReadXMLFile.getString was not the data whose integrity was being tested but rather the encoded signature itself. See our discussion for the resolution!


    Your code is wrong — you’re trying to compare the RSA-encrypted SHA1 digest of the base64-decoded ReadXMLFile.getString() to itself.

    final byte[] data = Base64.decode(ReadXMLFile.getString().getBytes());
    sig.update(data);
    boolean verifies = sig.verify(data);
    

    From the specification for Signature.update:

    Updates the data to be signed or verified, using the specified array of bytes.

    Then, from Signature.verify:

    Verifies the passed-in signature.

    Now, you’re not actually passing the signature data into verify! Did you mean to do sig.verify(Base64.decode(sign)) instead?

    If you need further proof, post pub.arm and I can demonstrate working, correct code 🙂

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

Sidebar

Related Questions

I found similar questions and answers like this one . However, as I tried
I've searched for similar questions but still have not found a solution as to
I've looked through the similar questions and not yet found an answer. I will
I found a couple questions similar to this, but not specifically for .NET projects,
I've tried searching for people with similar questions, but haven't found anything. I have
[Not a duplicate of similar questions as explained further down] I'm getting a code
I found similar questions but no answer to what I am looking for. So
I ran a quick google and SO search and found similar questions but none
I've found some similar questions on StackOverflow, but nothing that addresses what I'm looking
I know that this is a repeated question. I have found very similar questions

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.