PKCS#7 structure from PKCS#1 raw sign

2019-03-04 17:30发布

问题:

I'm able to sign a document hash with SecKeyrawsign method. The problem is seckeyrawsign method providing only pkcs#1 structure signature, but I want pkcs#7 format for CMS signing. Could you please tell me how to form pkcs#1 to pkcs#7 in ios.

unsigned char sha_buffer[SHA256_DIGEST_LENGTH];
    memset((void*) sha_buffer, 0, SHA256_DIGEST_LENGTH);
    SHA256_Final(sha_buffer, &m_sha_ctx);

    // Build signature - step 2: Sign hash

    uint8_t signature[256];
    size_t signature_len = sizeof(signature);
    OSStatus osrc = SecKeyRawSign(
                                  PEKey,
                                  kSecPaddingPKCS1SHA256,
                                  sha_buffer, sizeof(sha_buffer),
                                  signature, &signature_len
                                  );
    assert(osrc == noErr);