You can try to do it using the OpenSSL libraries, which comes complete with Caché/Ensemble/etc. To google: "openssl rsa-pss sign", "openssl SHA256 with RSA PSS padding"
Here is a small example on Windows, where it is assumed that
- cert.pem is your certificate:
-----BEGIN CERTIFICATE----- <...> -----END CERTIFICATE-----
- key.pem is your private key:
-----BEGIN RSA PRIVATE KEY----- <...> -----END RSA PRIVATE KEY-----
@echo off echo Delete all temporary files del /Q /F test.txt test.sig pubkey.pem test.b64 echo Extract the public key from certificate (only be done once) openssl x509 -pubkey -in cert.pem -noout > pubkey.pem echo Create test file (test.txt) echo bla-bla-bla test123 {Date}{newline}{Password}{newline}{etc}{Message Body} > test.txt echo Create signature (test.sig) openssl dgst -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1 -sign key.pem -out test.sig test.txt echo This step is only for information/verification. echo Verify signature (The result should be: "Verified OK") openssl dgst -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1 -signature test.sig -verify pubkey.pem test.txt echo Convert signature to Base64 (test.b64) echo You can this step be make on COS. openssl base64 -in test.sig -out test.b64 -nopad
Or on COS:
<FONT COLOR="#0000ff">#include </FONT><FONT COLOR="#000000">%systemInclude
</FONT><FONT COLOR="#0000ff">#include </FONT><FONT COLOR="#000000">%occErrors
</FONT><FONT COLOR="#ff0000">main</FONT><FONT COLOR="#000000">() </FONT><FONT COLOR="#0000ff">public </FONT><FONT COLOR="#800080">{
</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">fileMsg</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"test.txt"</FONT><FONT COLOR="#000000">,
</FONT><FONT COLOR="#800000">fileSig</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"test.sig"</FONT><FONT COLOR="#000000">,
</FONT><FONT COLOR="#800000">file64</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"test.b64"</FONT><FONT COLOR="#000000">,
</FONT><FONT COLOR="#800000">filePubKey</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"pubkey.pem"</FONT><FONT COLOR="#000000">,
</FONT><FONT COLOR="#800000">fileCert</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"C:\SSL\cert.pem"</FONT><FONT COLOR="#000000">,
</FONT><FONT COLOR="#800000">fileKey</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"C:\SSL\key.pem"
</FONT><FONT COLOR="#0000ff">try </FONT><FONT COLOR="#800080">{
</FONT><FONT COLOR="#0000ff">$$$AddAllRoleTemporaryInTry
n $namespace
if </FONT><FONT COLOR="#000000">'</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%File</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">Exists</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">filePubKey</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800080">{
</FONT><FONT COLOR="#008000">; Only be done once
; Extract the public key from certificate
</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">cmd</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$$$FormatText</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"openssl x509 -pubkey -in %1 -noout > %2"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">fileCert</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">filePubKey</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">cmd</FONT><FONT COLOR="#000000">,!!
</FONT><FONT COLOR="#0000ff">d $zf</FONT><FONT COLOR="#000000">(-1,</FONT><FONT COLOR="#800000">cmd</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#800080">}
</FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">fileMsg</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">fileSig</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">file64 </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%File</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">Delete</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">file</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Stream.FileCharacter</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">()
</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">file</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Filename</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">fileMsg
</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">file</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">TranslateTable</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"UTF8"
</FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">file</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">WriteLine</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"{Date}"</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">file</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">WriteLine</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"{Password}"</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">file</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Write</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"{etc}{Message Body}"</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#0000ff">$$$ThrowOnError</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">file</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%Save</FONT><FONT COLOR="#000000">())
</FONT><FONT COLOR="#0000ff">w $$$FormatText</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"Create signature (%1)"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">fileSig</FONT><FONT COLOR="#000000">),!
</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">cmd</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$$$FormatText</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"openssl dgst -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1 -sign %1 -out %2 %3"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">fileKey</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">fileSig</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">fileMsg</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">cmd</FONT><FONT COLOR="#000000">,!!
</FONT><FONT COLOR="#0000ff">d $zf</FONT><FONT COLOR="#000000">(-1,</FONT><FONT COLOR="#800000">cmd</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#0000ff">w $$$FormatText</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"Convert signature to Base64 (%1)"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">file64</FONT><FONT COLOR="#000000">),!
</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">cmd</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$$$FormatText</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"openssl base64 -in %1 -out %2 -nopad"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">fileSig</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">file64</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">cmd</FONT><FONT COLOR="#000000">,!!
</FONT><FONT COLOR="#0000ff">d $zf</FONT><FONT COLOR="#000000">(-1,</FONT><FONT COLOR="#800000">cmd</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#008000">;here we read our file test.b64 (file64) and place it in a Signature field in the header
</FONT><FONT COLOR="#800080">}</FONT><FONT COLOR="#0000ff">catch</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">ex</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800080">{
</FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"Error "</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">ex</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">DisplayString</FONT><FONT COLOR="#000000">(),!
</FONT><FONT COLOR="#800080">}
</FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">fileMsg</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">fileSig </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%File</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">Delete</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#800080">}</FONT>
- Log in to post comments