digital-signature

XML Signature: How to calculate the digest value?

烈酒焚心 提交于 2019-11-28 20:09:18
问题 I have an XML like this <?xml version="1.0" encoding="utf-8"?> <foo> <bar> <value>A</value> </bar> <bar> <value>B</value> </bar> <baz> <value>C</value> </baz><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />

How to add digital signature (RSA, Certificate, etc) to any of file, using PHP?

☆樱花仙子☆ 提交于 2019-11-28 19:54:47
I need to know if any kind of file can be signed digitally, using RSA, a certificate, and that stuff, or if only certain kind of files can be signed. All this, using PHP. In example: Can a plain text file be signed digitally?, What about images (png, jpeg, bmp)? I don't need to "attach" an image with a graphic signature. Thank you for your help. neubert Using phpseclib, a pure PHP RSA implementation (updated here ): <?php include('Crypt/RSA.php'); $rsa = new Crypt_RSA(); extract($rsa->createKey()); $plaintext = 'terrafrost'; $rsa->loadKey($privatekey); $signature = $rsa->sign($plaintext); $rsa

Digital certificates: What is the difference between encrypting and signing

≡放荡痞女 提交于 2019-11-28 18:03:11
问题 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 not true. Is it correct? Or is it one to one mapping? So, the way digital signature works is that the content of a certificate is hashed and then "signed" with a private key. The signature is verified then with the corresponding public key. So,

Verify RFC 3161 trusted timestamp

那年仲夏 提交于 2019-11-28 17:19:26
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 and asymmetric cryptography functionality readily at my disposal.) RFC 3161, with its reliance on ASN.1 and X.690 and whatnot, is not simple to implement, so for now at least, I'm using Bouncy Castle to generate the TimeStampReq (request) and parse the TimeStampResp (response). I just can't quite figure out how to validate the response. So far, I've

Difference between SHA256withRSA and SHA256 then RSA

一世执手 提交于 2019-11-28 17:15:40
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 Signature.getInstance("RSA"); to get the signature? If they are different, is there a way to modify the method 2 so that both methods give the same output? I tried the following code: package mysha.mysha; import java.security.MessageDigest; import java.security.PrivateKey; import java.security.Security; import java.security.Signature; import org.bouncycastle.jce

HMAC-SHA256 Algorithm for signature calculation

醉酒当歌 提交于 2019-11-28 16:38:22
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 secret_key = new javax.crypto.spec.SecretKeySpec(asciiCs.encode("key").array(), "HmacSHA256"); final byte[] mac_data = sha256_HMAC.doFinal(asciiCs.encode("The quick brown fox jumps over the lazy dog").array()); String result = ""; for (final byte element : mac_data) { result += Integer.toString((element & 0xff) + 0x100, 16).substring(1); } System.out

How to programatically sign an MS office XML document with Java?

随声附和 提交于 2019-11-28 14:43:30
Please, could someone point me in the right direction to digitally sign an MS-Office document (docx, xlsx, pptx) in Apache POI, or any other open source library? I have already reviewed the classes under org.apache.poi.openxml4j.opc.signature but I cannot understand how I could add a signature to a document. Check this sample code .. this sample code uses a file keystore PFX (PKCS12) .. Signs the Document and verify it. // loading the keystore - pkcs12 is used here, but of course jks & co are also valid // the keystore needs to contain a private key and it's certificate having a //

Sign PDF using an external service and iText

不问归期 提交于 2019-11-28 14:03:57
I have this scenario. I have an application that generates a PDF, and that needs to be signed. We have not the certificates to sign the document, because they're in a HSM, and the only way we could make use of the certificates is using a webservice. This webservice, offers two options, send the PDF document, and it returns a signed pdf, or send a hash that will be signed. The first option, is not viable, because the PDF is signed without a timestamp (this is a very important requisite), so the second option is chosen. This is our code, first, we get the signature appearance, and calculate the

How to create precofigured installer (MSI or EXE) with valid signature?

半城伤御伤魂 提交于 2019-11-28 12:18:46
We want our users to download preconfigured installers of our software for Windows. Pre-configured data consists of settings based on user account data. The customization is to be done in a Java server running on Linux. We need to have those installers digitally signed. Unfortunately we cannot have private signing key on those servers, due to security policy. Can you think of ways to put some metadata into either MSI or EXE while preserving digital signature or other approaches to fulfill the use case? EDIT : The requirement is to have a single file download, so unfortunately parallel ini file

Message digest of pdf in digital signature

泄露秘密 提交于 2019-11-28 11:44:37
I want to manually verify the integrity of a signed pdf. I have been able to reach at:- got the value of '/Content' node from pdf(using PyPDF2 ). This is a der encoded PKCS#7 certificate. Now as per pdf specifications , the message digest of the pdf data is stored along with the certificate in /Content node. Tried a lot but I am not able to get the digest value which I would eventually compare with hashed pdf content(specified by /ByteRange ). PDF specification snapshot:- Don't understand the last part that says write signature object data into the dictionary . where does this write actually