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
33
votes
4 answers

openssl command line to verify the signature

Hi I have generated a key pair and used the private key to generate a signature. openssl rsautl -sign -in helloworld.txt -inkey aa.pem -out sig However I am unable to verify the signature with my public key: openssl rsautl -verify -in…
c2h2
  • 11,911
  • 13
  • 48
  • 60
33
votes
5 answers

Correct way to sign and verify signature using bouncycastle

I am using bcmail-jdk16-1.46.jar and bcprov-jdk16-1.46.jar (Bouncycastle libraries) to sign a string and then verify the signature. This is my code to sign a string: package my.package; import java.io.FileInputStream; import…
Oscar Jara
  • 14,129
  • 10
  • 62
  • 94
31
votes
4 answers

Questions about preparing an apk for the Amazon Android App Store

Amazon's documentation is surprising lacking in information about the submitting binary process. From what I can tell, you submit an unsigned binary and they wrap it in their own code and produce a signed apk? This leaves several questions: Does…
cottonBallPaws
  • 21,220
  • 37
  • 123
  • 171
30
votes
2 answers

Checking digital signature programmatically from Delphi

I need a function in Delphi to verify the digital signature of an external EXE or DLL. In my particular application, I am going to occasionally invoke other processes, but for security purposes I want to make sure these executables were created by…
kes
  • 5,983
  • 8
  • 41
  • 69
30
votes
4 answers

What is contained in "./META-INF/CERT.RSA" file for an Android app?

I am new to cryptography certificate and am trying to figure out the components of "CERT.RSA" file under "./META-INF" folder for an Android application. To my understanding, "CERT.RSA" is used to verify the signiture of "CERT.SF" file under the same…
28
votes
6 answers

What is the purpose of using separate key pairs for signing and encryption?

Why do I need to use separate public key pairs for signing and encryption and not use the same key pair with RSA for example? Is there any security problem with using the same key?
gil regev
  • 281
  • 1
  • 3
  • 3
27
votes
2 answers

Difference between openSSL rsautl and dgst

The following command generates a signature for an input file: openssl dgst -sha1 -sign privateKey.pem -out signature1 someInputFile The following commands also generates a signature for an input file: openssl dgst -binary -sha1 someInputFile >…
fishinear
  • 6,101
  • 3
  • 36
  • 84
27
votes
4 answers

Why does git sign with GPG keys rather than using SSH keys?

What are the differences between SSH and GPG asymmetric keys and why does git support signing with GPG rather than using the SSH agent?
Dan Kowalczyk
  • 4,103
  • 2
  • 18
  • 29
27
votes
3 answers

Is it possible to add a signature field in a pdf document using PHP? I haven't to "digital sign" document. I only add a signature field.

I have to generate a PDF document and add a "signature field". A signature field is a field that allow to third party service to digitally sign document. Is it possible to do this in PHP with an open source solution ? I saw…
27
votes
4 answers

XML Signature: How to calculate the digest value?

I have an XML like this A B C
user252816
  • 563
  • 4
  • 12
  • 21
26
votes
4 answers

When should I use SHA-1 and when should I use SHA-2?

In my c# application, I'm using RSA to sign files before being uploaded on the database of my company by the person who is uploading and here I have to choose SHA-1 or SHA-2 for computing the hash. As any other component in programming, I know that…
Majd
  • 1,358
  • 3
  • 15
  • 29
26
votes
4 answers

How can I digitally sign an executable?

I'm coding software that requires administrative access. When a UAC dialog pops up, it shows a different popup for digitally signed software than non-signed software. I believe digitally signing my software would enable users to trust my software…
Rudi
  • 341
  • 2
  • 5
  • 6
26
votes
2 answers

Wrong digest value for xml signatures using Java XML Digital Signature API

I need to send a signed XML file to a government agency in Brazil. The problem is that the digest calculated by my Java code (using the Java XML Digital Signature API is different from the one generated with another tool like XMLSEC. Here's the code…
Andre
  • 3,874
  • 3
  • 35
  • 50
25
votes
4 answers

SignedXml Compute Signature with SHA256

I am trying to digitally sign a XML document using SHA256. I am trying to use Security.Cryptography.dll for this. Here is my code…
th1rdey3
  • 4,176
  • 7
  • 30
  • 66
25
votes
1 answer

How to Verify Signature, Loading PUBLIC KEY From CRT file?

I reviewed many forums and examples, but none helped me. I need verify signature from any webservice. I have test.crt file with public key for verify. static bool Verify(string text, string signature) { X509Certificate2 cert = new…
drup
  • 365
  • 3
  • 10