Skip to content

Convert PKCS#7 / CMS data to JOSE

Inspect a PKCS#7 / CMS file to learn what converting it needs, then convert it to JOSE: signed data becomes a JWS, enveloped data a JWE, and signed-and-enveloped data a JWE whose plaintext is a JWS. The conversion changes the container, not the algorithms; classical algorithms are kept, and CBC content encryption becomes GCM.

Who can do it

An application authenticated as a cryptographic actor of your tenant:

  • Analysis needs the scope migration.analyzePkcs7. It decrypts nothing and uses no key.
  • Conversion needs the scope migration.convertPkcs7, plus Capability Grants on the keys involved: REENCRYPT over the decrypting key and each recipient key, and RESIGN over each signer's key.

No console role performs these operations.

Before you start

  • The application can obtain a token. See Get an access token for an application.
  • For a conversion, every signer and every recipient of the file has a key in your tenant whose certificate carries that actor's issuer and serial number. Every signer needs its private key imported. The recipient you decrypt with needs a key that can decrypt and encrypt; every other recipient a key that can encrypt. A certificate imported alone is verify-only and is refused for every signer and recipient.

Steps

  1. Analyze the file first:
    • Java SDK: sdk.analyzePkcs7(request) with a Pkcs7AnalysisRequest, or sdk.analyzePkcs7Stream(file) for a large file.
    • Crypto CLI: AnkaSecureCLI analyze-pkcs7 --input-file <file>, or analyze-pkcs7-stream for a large file; --output-file keeps the report.
    • API: POST /api/v3/migration/analyze-pkcs7 with the Base64 file in pkcs7Data, or POST /api/v3/migration/stream/analyze-pkcs7 with a multipart/form-data body, metadata before file.
  2. Read the report: supportStatus says whether the structure can be converted, and recommendations.requiredKeys names, by issuer and serial number, every key the conversion needs.
  3. Import any missing key, then convert:
    • Java SDK: sdk.convertPkcs7ToJose(request) with a Pkcs7ConversionRequest, or sdk.convertPkcs7ToJoseStream(metadata, inputFile, outputFile) for a large file.
    • Crypto CLI: AnkaSecureCLI convert-pkcs7 --input-file <file> --output-file <file>, with --decrypt-kid <kid> to choose the recipient to decrypt with, --serialization and --target-format; convert-pkcs7-stream for a large file.
    • API: POST /api/v3/migration/convert-pkcs7-to-jose, or POST /api/v3/migration/stream/convert-pkcs7-to-jose for a large file.
  4. Choose the serialization: AUTO (the default) produces the compact form for at most one signer and one recipient and the General JSON form otherwise; COMPACT and JSON force one.

What you see when it worked

The analysis lists every signer and recipient, the algorithms and certificates, the JOSE form a conversion would produce, and every key it needs.

The conversion returns the JOSE token with one signature per signer key and one recipient per recipient key, and maps each original signer and recipient to the key identifier that now stands for it. Every CMS signature is verified before it is re-signed. The streaming conversion writes a detached JWS for signed data and a multipart JWE for enveloped data.

If it fails

What you see Cause What to do
400 .../errors/invalid-pkcs7 or .../errors/invalid-input The file is not a valid PKCS#7 / CMS structure, is not valid Base64, or a parameter is outside its vocabulary Check the file and the request
422 .../errors/unsupported-pkcs7-format with UNSUPPORTED_SIGNER_IDENTIFIER or UNSUPPORTED_RECIPIENT_TYPE A signer is identified by subject key identifier, or a recipient is not RSA key transport named by issuer and serial number The file cannot be converted as it is
422 with MISSING_SIGNER_KEY, MISSING_RECIPIENT_KEY, MISSING_RECIPIENT_PRIVATE_KEY or MISSING_ACTOR_KEYS A signer or recipient has no suitable key in the tenant Import the key the analysis names, then retry
422 with INCOMPATIBLE_SERIALIZATION COMPACT was requested for more than one signer or recipient Use AUTO or JSON
422 with DECRYPTION_FAILED The content could not be decrypted with the chosen recipient's key Check the decrypting key
403 .../errors/forbidden The token lacks the scope, the actor lacks a grant on a key, or the tenant or actor is not in a state that permits the operation Ask a tenant administrator to check the actor's roles and grants
404 A named key, or its certificate, does not exist in the tenant Check the key identifier
409 .../errors/key-protection-backend-not-configured The tenant has no key protection backend A tenant administrator configures it
413 The file is above the one-request limit Use the streaming operation

Without the console

These operations have no console screen.

Surface How
Java SDK analyzePkcs7, analyzePkcs7Stream, convertPkcs7ToJose, convertPkcs7ToJoseStream on AuthenticatedSdk
Crypto CLI AnkaSecureCLI analyze-pkcs7, analyze-pkcs7-stream, convert-pkcs7, convert-pkcs7-stream
API POST /api/v3/migration/analyze-pkcs7 (analyzePkcs7), POST /api/v3/migration/stream/analyze-pkcs7 (analyzePkcs7Stream), POST /api/v3/migration/convert-pkcs7-to-jose (convertPkcs7ToJose), POST /api/v3/migration/stream/convert-pkcs7-to-jose (convertPkcs7ToJoseStream)