PKCS12.SignData
---------------

Creates a PKCS#7 signature for given data.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Certificates](component_Certificates.md) | [13.1](newinversion131.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "PKCS12.SignData"; PKCS12 Reference; InputType; InputData; InputEncoding; OutputType { ; OutputInfo } ) 

**MBS**( **"PKCS12.SignData";** /\* Creates a PKCS#7 signature for given data. \*/  
**$PKCS12 Reference**; /\* The reference to the PKCS12.e.g. $pkcs12 \*/   
**$InputType**; /\* The type of input.   
Can be Text, Container, Image, Path, PDF, Data, base64 or Hex.e.g. "Text" \*/   
**$InputData**; /\* The actual input data.   
Text, container or file path.e.g. "Hello World" \*/   
**$InputEncoding**; /\* The text encoding for text input.   
Parameter is ignored for other cases.e.g. "UTF-8" \*/   
**$OutputType**; /\* The output type.   
Can be Base64, Hex, Text, File, Path.  
Can be Auto in plugin version 7.3 to detect type for container from OutputInfo parameter.  
Added Base64URL as option for plugin version 10.3.e.g. "Hex" \*/   
**$OutputInfo**) /\* Optional; The addition info for output.   
For text it is the text encoding, for file container the file name and for path the actual native file path.e.g. "" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| PKCS12 Reference | The reference to the PKCS12. | $pkcs12 |  |
| InputType | The type of input.    Can be Text, Container, Image, Path, PDF, Data, base64 or Hex. | "Text" |  |
| InputData | The actual input data.    Text, container or file path. | "Hello World" |  |
| InputEncoding | The text encoding for text input.    Parameter is ignored for other cases. | "UTF-8" |  |
| OutputType | The output type.    Can be Base64, Hex, Text, File, Path.   Can be Auto in plugin version 7.3 to detect type for container from OutputInfo parameter.   Added Base64URL as option for plugin version 10.3. | "Hex" |  |
| OutputInfo | The addition info for output.    For text it is the text encoding, for file container the file name and for path the actual native file path. | "" | Optional |

### Result

Returns OK or error.

### Description

Creates a PKCS#7 signature for given data.  
Signs the data and returns signature as a PKCS#7 for the given data.  
### Examples

Manually sign PDF content:

 # manually load certificate and key   
Set Variable \[ $pkcs12 ; Value: MBS ( "PKCS12.ReadFromFile"; "/Users/cs/Desktop/test\_cert.pfx"; "123456") \]   
\# sign a test string to know size in advance   
Set Variable \[ $SampleSignature ; Value: MBS ( "PKCS12.SignData"; $pkcs12 ; "hex"; "C9097E23869BC9903CE89E9562230C6FDCBC0F06"; ""; "hex"; "" ) \]   
Set Variable \[ $estimatedSignatureSize ; Value: Length($SampleSignature ) / 2 + 5 \]   
\# now save and produce hash   
Set Variable \[ $hashToSign ; Value: MBS ("[DynaPDF.SaveAndSignFileExt1](DynaPDFSaveAndSignFileExt1.md)"; $pdf ; "My ContactInfo"; "My Location"; "My Reason"; "My Signer"; $estimatedSignatureSize ) \]   
\# sign the hash   
Set Variable \[ $Signature ; Value: MBS ( "PKCS12.SignData"; $pkcs12 ; "hex"; $HashToSign ; ""; "hex"; "" ) \]   
\# and finish the PDF   
Set Field \[ Merge PDFs::MergeStatus ; MBS ("[DynaPDF.SaveAndSignFileExt2](DynaPDFSaveAndSignFileExt2.md)"; $pdf ; $signature ; "Merged.pdf") \]  
### See also

- [DynaPDF.Save](DynaPDFSave.md)
- [DynaPDF.SaveAndSignFile](DynaPDFSaveAndSignFile.md)
- [DynaPDF.SaveAndSignFileExt](DynaPDFSaveAndSignFileExt.md)
- [DynaPDF.SaveAndSignFileExt1](DynaPDFSaveAndSignFileExt1.md)
- [DynaPDF.SaveAndSignFileExt2](DynaPDFSaveAndSignFileExt2.md)
- [PKCS12.ReadFromFile](PKCS12ReadFromFile.md)

### Release notes

- **Version 13.1**
    - Added [PKCS12.SignData](https://www.mbsplugins.eu/PKCS12SignData.shtml) function.

This function checks for a license.

Created 28th February 2023 , last changed 10th March 2023

  
[PKCS12.ShowDialog](PKCS12ShowDialog.md) - [PKCS7.List](PKCS7List.md)

[HTML Version](PKCS12SignData.shtml)