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
23
votes
8 answers

Error occurred while decoding OAEP padding

While decrypting text using RSACryptoServiceProvider.Decrypt, I am getting the error: Error occurred while decoding OAEP padding. Here's my code: CspParameters cspParam = new CspParameters(); cspParam = new CspParameters(); cspParam.Flags =…
23
votes
7 answers

PKIX path validation failed: java.security.cert.CertPathValidatorException: signature check failed

From Pro Spring Security book by Carlo Scarioni, I'm trying to integrate Spring Application with CAS Server. I followed every step that the book instructed, still I'm stuck with this error. Please help me out. SEVERE:…
user961690
  • 698
  • 1
  • 11
  • 22
22
votes
6 answers

XML dig sig error after upgrade to java7u25

I have a Java application for signing XML documents. After upgrading Java to the latest version (Java7u25) it stops working. I get the following error: javax.xml.crypto.dsig.XMLSignatureException: javax.xml.crypto.URIReferenceException:…
kresok
  • 223
  • 1
  • 2
  • 4
21
votes
4 answers

How to retrieve digital signature information from PDF with PHP?

I have app that needs to retrieve some data (signer name) from digital signature "attached" on PDF files. I have found only examples in Java and C# using the iText class AcroFields method GetSignatureNames edit: I've tried pdftk with…
celsowm
  • 846
  • 9
  • 34
  • 59
21
votes
5 answers

Digital certificates: What is the difference between encrypting and signing

I am relatively new to PKI, certificates and all related stuff. As far as I understand in public-key cryptography one encrypt with a public key and decrypt with a private key. Only one private key can correspond to any public key but the opposite is…
user1745356
  • 4,462
  • 7
  • 42
  • 70
21
votes
5 answers

How to retrieve my public and private key from the keystore we created

My task is the following: Retrieve my public and private key from the keystore I created. Use these keys to encrypt a paragraph using my RSA 2048-bit public key. Digitally sign the result using the DSA-SHA-1 signature algorithm. Save the digital…
Zack Ef
  • 313
  • 1
  • 2
  • 5
20
votes
2 answers

Is there a standardized fixed-length encoding for EC public keys?

I was wondering if there was (and I hope there is) a standard for public key size for ECDH (Elliptic Curve Diffie-Hellman) and ECDSA (Elliptic Curve Digital Signature Algorithm) for every curve type over prime fields (192, 224, 256, 384 and 521).
20
votes
3 answers

m_safeCertContext is an invalid handle

I've been wrestling with a problem, maybe you guys can point me in the right direction. I'm trying to digitally sign a pdf, on the webserver, over an https connection. At page load i'm doing as so: HttpClientCertificate cs =…
Sergio
  • 8,125
  • 10
  • 46
  • 77
20
votes
3 answers

Is there an easier way to sign an XML document in Java?

I'm trying to digitally sign an XML document using Java. I've got an implementation working with some references I've found that use various implementations in the javax.xml.crypto.dsig package. However, my current implementation is like many of the…
Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
20
votes
4 answers

How to validate if a signed jar contains a timestamp?

After a jar is signed and the -tsa option was used, how can I validate that the time stamp was included? I tried: jarsigner -verify -verbose -certs myApp.jar But the output does not specify anything about the time stamp. I'm asking because even if…
user199092
  • 293
  • 1
  • 2
  • 11
20
votes
2 answers

Tutorial of ECDSA algorithm to sign a string

Can you help me to find a simple tutorial of how sign a string using ECDSA algorithm in java. But without using any third-party libraries like bouncycastle. Just JDK 7. I found it difficult to search a simple example, I'm new to…
user1379574
  • 689
  • 4
  • 11
  • 23
19
votes
2 answers

NDK application Signature Check

I have some security key in an application. I want to store it securly. I like to store it in a native shared library (maybe generated from some code). After that I want it to be returned by a method that will check the signature of the original…
Yevgen Kulik
  • 5,713
  • 2
  • 22
  • 44
19
votes
2 answers

Digitally sign data in browser using smart card or certificate

I need to create digital signature of some XML data with a client certificate(smart card) using web browser. Usually I used to do it with a java applet executing on the client side. The benefit being multiplatform in terms of OS and browsers.…
Plamen Ignatov
  • 612
  • 1
  • 7
  • 17
19
votes
3 answers

Verify RFC 3161 trusted timestamp

In my build process, I want to include a timestamp from an RFC-3161-compliant TSA. At run time, the code will verify this timestamp, preferably without the assistance of a third-party library. (This is a .NET application, so I have standard hash…
P Daddy
  • 28,912
  • 9
  • 68
  • 92
19
votes
3 answers

What do I need to know about XML Signatures to get SAML working?

At work we have a web app that we'll need to interface with another company's web app using Single Sign On validated by SAML. Our web apps are written in PHP, and it's obviously irrelevant what language choice the other company is using.…
soapergem
  • 9,263
  • 18
  • 96
  • 152