Note that there are some explanatory texts on larger screens.

plurals
  1. POJava, Digital Signature with BouncyCastle
    text
    copied!<p>In Java, I tried to sign a byte[] (which is my sha256 digest of my document) with bouncy castle and a certificate in this specification: </p> <p><a href="http://www.ebics.org/fileadmin/unsecured/specification/spec_current_EN/EBICS_Specification_2.5_final-16-05-2011.pdf" rel="nofollow">http://www.ebics.org/fileadmin/unsecured/specification/spec_current_EN/EBICS_Specification_2.5_final-16-05-2011.pdf</a></p> <p>in chapter 14.1.4.1.1 Digital signature generation.</p> <p>I found in bouncy's java doc this method:</p> <pre><code>public static byte[] signer(byte[] datas, Certificat cert) { try { List&lt;X509Certificate&gt; certList = new ArrayList&lt;X509Certificate&gt;(); CMSTypedData msg = new CMSProcessableByteArray(datas); certList.add(cert.getCertificat()); Store certs = new JcaCertStore(certList); CMSSignedDataGenerator gen = new CMSSignedDataGenerator(); ContentSigner sha256signer = new JcaContentSignerBuilder( "SHA256withRSA").setProvider("BC").build( cert.getPrivateKey()); gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder( new JcaDigestCalculatorProviderBuilder().setProvider("BC") .build()).build(sha256signer, cert.getCertificat())); gen.addCertificates(certs); CMSSignedData sigData = gen.generate(msg, true); return sigData.getEncoded(); } catch (Exception e) { throw new RuntimeException( "Erreur lors de la signature du document", e); } </code></pre> <p>I don't know if this signature is really in accordance with PKCS#1 1.5 required by the specification. Do I have to add the padding manually? And the OID for RSA256?</p>
 

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