Questions tagged [digital-signature]

mathematical scheme for demonstrating the authenticity of a digital message or document (Wikipedia). A cryptographic toolkit is often used along with a public-private key pair to digitally sign a message and to verify a message.

Digital signatures are often used in a cryptographically secure message exchange to provide:

  • Authentication - proof that a message was sent from a trusted party
  • Integrity - proof that a message was not tampered with in transit
  • Non-repudiation - the receiver can proof to a third party that the message originated from the original sender

Message authentication codes (MAC) also offer authentication and integrity protection, but no non-repudiation.

Digital signatures generally make use of a public-private key pair. A private key is used to sign the message and a public key is used to verify the integrity and authenticity of a message.

If a message has been tampered with or was not signed by the expected party the verification of the signature will fail.

An example of digitally signing a simple message in java then verifying the result:

KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); 
KeyPair keyPair = kpg.generateKeyPair();

byte[] message = "My message is strong!".getBytes();

// Sign our message
Signature signer = Signature.getInstance("SHA1withRSA");
signer.initSign(keyPair.getPrivate());
signer.update(message);
byte[] signatureData = signer.sign();

// Verify our message using the public key + signatureData
Signature verifier = Signature.getInstance("SHA1withRSA");
verifier.initVerify(keyPair.getPublic());
verifier.update(message);

assertTrue(verifier.verify(signatureData));

See also:

3380 questions
343
votes
6 answers

How do I find out which keystore was used to sign an app?

I have an app which is signed and several keystore files. I'd like to update the app, so I need to find out which one of keys was used. How can I match which keystore was used to originally sign my app against various keystores I have on my machine?
xliiv
  • 5,399
  • 5
  • 29
  • 35
328
votes
10 answers

How does a public key verify a signature?

I am trying to get a better grapple on how public/private keys work. I understand that a sender may add a digital signature to a document using his/her private key to essentially obtain a hash of the document, but what I do not understand is how the…
242
votes
17 answers

app-release-unsigned.apk is not signed

I downloaded the zip file of an Android app on github and I'm trying to run it, but I get a dialog with this message app-release-unsigned.apk is not signed. Please configure the signing information for the selected flavor using the Project Structure…
andrew
  • 3,879
  • 4
  • 25
  • 43
93
votes
9 answers

HMAC-SHA256 Algorithm for signature calculation

I am trying to create a signature using the HMAC-SHA256 algorithm and this is my code. I am using US ASCII encoding. final Charset asciiCs = Charset.forName("US-ASCII"); final Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); final SecretKeySpec…
Rishi
  • 1,331
  • 4
  • 13
  • 16
71
votes
7 answers

Using SHA1 and RSA with java.security.Signature vs. MessageDigest and Cipher

I'm trying to understand what the Java java.security.Signature class does. If I compute an SHA1 message digest, and then encrypt that digest using RSA, I get a different result to asking the Signature class to sign the same thing: // Generate new…
Kothar
  • 6,579
  • 3
  • 33
  • 42
64
votes
6 answers

Securing an API: SSL & HTTP Basic Authentication vs Signature

When designing an API for our web app, we'll use the their subdomain as the 'username' and generate an API key/shared secret. Firstly, is it ok to use the subdomain as the username? I don't see the benefit of generating another key. Different APIs…
Marcus
  • 9,011
  • 10
  • 45
  • 65
62
votes
4 answers

Digitally sign PDF files

I have a digital certificate that identifies a user. I need to use it to Digitally sign pdf files. Does anyone have an example that does not uses a third party component? I need to get this done but it would be nice to fully understand how things…
Sergio
  • 8,125
  • 10
  • 46
  • 77
57
votes
1 answer

How to create public and private key with openssl?

My questions are How to create a public key and private key with OpenSSL in windows? How to put the created public key in .crt file and the private one in .pcks8 file I want to use these two keys to sign a SAML assertion in Java. Thanks in…
Karim
  • 637
  • 1
  • 5
  • 13
53
votes
10 answers

what is the difference between digital signature and digital certificate?

i've been google'ing the difference between digital signature and digital certificate (asymmetric encryption) seems like they are the same. I would like to clarify if they are the same or not? many thanks!!!
Bugzy bug
  • 621
  • 2
  • 8
  • 13
46
votes
3 answers

Understanding RSA signing for JWT

I'm implementing a sign in system with the help of the JWT (JSON Web Token) scheme. Basically, after a user sign in / login, the server signs a JWT and passes it to the client. The client then returns the token with each request and the server…
Liran Cohen
  • 1,190
  • 1
  • 9
  • 16
43
votes
1 answer

RSA signature size?

I would like to know what is the length of RSA signature ? Is it always the same size as the RSA key size like if the key size is 1024 then RSA signature is 128 bytes , if the key size is 512 bits then RSA signature is 64 bytes ? what is RSA modulus…
user839917
  • 851
  • 5
  • 13
  • 20
43
votes
1 answer

Verify a signature in JWT.IO

I have generated the following token and am trying to verify the signature with http://jwt.io I have also attached the contents of my jwks endpoint that should have all the details I need to verify. So my question is: how do I get this to say…
Jeremy Gray
  • 1,378
  • 1
  • 9
  • 24
39
votes
2 answers

Difference between SHA256withRSA and SHA256 then RSA

What is the difference between compute a signature with the following two methods? Compute a signature with Signature.getInstance("SHA256withRSA") Compute SHA256 with MessageDigest.getInstance("SHA-256") and compute the digest with…
Greenhand
  • 681
  • 2
  • 9
  • 17
39
votes
1 answer

Does anyone know a free(trial) timestamp server service?

Would like to know if anybody knows any free(trial) time-stamp server service. I would like to test time stamping features in itext. Like I used Start Com class 1 as free CA for testing purposes. Hope I made it clear. Hoping someone knows a…
caniaskyouaquestion
  • 657
  • 2
  • 11
  • 21
33
votes
5 answers

How to sign string with private key

How can I get the signature of a string using SHA1withRSA if I already have the Private Key as byte[] or String?
xain
  • 13,159
  • 17
  • 75
  • 119
1
2 3
99 100