Firma Un docuemnto generico creando una Busta CADES a 256bit

In questo esempio di codice viene Firmato un Documento creando un file p7m con Busta Cades e firma cifrata con algoritmo sha-256 come richiesto dalla più recendi normative. Questo formato è obbligatorio a partire dal 30 giugno 2011

Esempio scritto in codice C che genera una Firma CADES sha-256 su un file genericp

#include "dimatec.h"

#define CRYPTO_PROVIDER_TYPE 3 //  esempio su XP

#define PKCS11_DLL "C:\\WINDOWS\\system32\\bit4ipki.dll" // usato da numerosi Token di Infocert ma non solo
#define PKCS11_LOW_LEVEL_ENABLED FALSE

int FirmaFile(char *FileDaFirmare, char *Pin)
{
    int ret;

    // Creo l'oggetto Dimatek
    HDMTOBJ hDmt = dmtCreate(
        0,
        "MY",
        PKCS11_DLL,
        CRYPTO_PROVIDER_TYPE,
        PKCS11_LOW_LEVEL_ENABLED);
    if (hDmt < 0)
        goto end;

    ret = dmtLoadCertificate(
        hDmt,
        "Franco Spinella",
        FALSE,"19029012"

       );
    if (ret != DMT_OK)
        return ret;
    ret = dmtSetDefaultCertificate(
        hDmt,
        0,
        FALSE);
    if (ret != DMT_OK)
        return ret;

    ret = dmtSigningFilewithCadesAttributes(
        hDmt,
        FileDaFirmare,
        "2.16.840.1.101.3.4.2.1", // szOID_NIST_sha256 - Algoritmo di Hash
        "1.2.840.113549.3.4", // szOID_RSA_RC4 - Algoritmo di Encode
        FALSE, // Detach
        FALSE, // Encrypt --> Cifra il contenuto
        FALSE, // Includi i certificati dei destinatati
        FALSE, // Cifra utilizzando tutti i certificati dei destinatari
        "11111111", // Pin della smart-card
        FALSE, // Aggiungi il TimeStamp
        "", // Time-Stamp da aggiungere
        ""  // Formato del Time-Stamp
        );
    if (ret != DMT_OK)
        goto end;

end:
    if ((ret == DMT_OK) && (hDmt > 0))
        MessageBox(NULL, "Funzione eseguita con successo", "DimatecTest", MB_OK);
    else if (ret == -1)
        dmtGetLastError(true);
    else
    {
        char ErrorBuffer[200];
        if (hDmt < 0)
            sprintf(ErrorBuffer, "Funzione eseguita con ERRORE: %i", hDmt);
        else
            sprintf(ErrorBuffer, "Funzione eseguita con ERRORE: %i", ret);

        MessageBox(NULL, ErrorBuffer, "DimatecTest", MB_OK);
    }

    if (hDmt > 0)
        dmtRelease(hDmt);

    return ret;
}
 





Per poter lasciare un commento ti devi loggare!