Note that there are some explanatory texts on larger screens.

plurals
  1. POCapicom and SHA1 - Help translating a java code to Delphi
    primarykey
    data
    text
    <p>I have a java application that signs a string using a certificate. It works encrypting the string it with SHA1. I am trying to translate the code to Delphi 2010, but I have no idea how to get it working the same way the java app does (using sha1). So far, I have found this:</p> <p><a href="https://stackoverflow.com/questions/1630714/delphi-7-access-windows-x509-certificate-store">Delphi 7 access Windows X509 Certificate Store</a> </p> <p>It does work, but it does not use sha1 and I get different results when I run the java app.</p> <h2>Java code</h2> <pre><code> char[] pass = (char[]) null; PrivateKey key = (PrivateKey) getKeyStore().getKey(alias, pass); Certificate[] chain = getKeyStore().getCertificateChain(alias); CertStore certsAndCRLs = CertStore.getInstance("Collection", new CollectionCertStoreParameters(Arrays.asList(chain)), "BC"); X509Certificate cert = (X509Certificate) chain[0]; CMSSignedDataGenerator gen = new CMSSignedDataGenerator(); gen.addSigner(key, cert, CMSSignedDataGenerator.DIGEST_SHA1); gen.addCertificatesAndCRLs(certsAndCRLs); CMSProcessable data = new CMSProcessableByteArray(conteudoParaAssinar); CMSSignedData signed = gen.generate(data, true, "SunMSCAPI"); byte[] envHex = signed.getEncoded(); CertInfo certInfo = new CertInfo(); certInfo.Hash = new BigInteger(envHex).toString(16); return certInfo; </code></pre> <h2>Delphi Code</h2> <pre><code>var lSigner: TSigner; lSignedData: TSignedData; fs: TFileStream; qt: integer; ch: PChar; msg : WideString; content : string; cert: TCertificate; begin cert := Self.GetCert; content := 'test'; lSigner := TSigner.Create(self); lSigner.Certificate := cert.DefaultInterface; lSignedData := TSignedData.Create(self); lSignedData.content := content; msg := lSignedData.Sign(lSigner.DefaultInterface, false, CAPICOM_ENCODE_BASE64); lSignedData.Free; lSigner.Free; </code></pre> <p><strong>EDIT</strong></p> <p>Based on the java code, should I get the cert info in binary format, apply sha1 on it and them convert it to hex? Is this the right order and the same thing the java code does? I can see some SHA1 constants in the capicom tlb as well as a hash class, maybe I should use those classes, but I dont know how.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload