PKCS12.ReadFromFile
-------------------

Reads certificate and private key from a PKCS12 file.

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

MBS( "PKCS12.ReadFromFile"; Path { ; Password } ) 

**MBS**( **"PKCS12.ReadFromFile";** /\* Reads certificate and private key from a PKCS12 file. \*/  
**$Path**; /\* The native file path to the PEM file.e.g. "/Users/cs/Desktop/test.pem" \*/   
**$Password**) /\* Optional; The password for the p12 file.e.g. "Hello" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| Path | The native file path to the PEM file. | "/Users/cs/Desktop/test.pem" |  |
| Password | The password for the p12 file. | "Hello" | Optional |

### Result

Returns PKCS12 reference number or error.

### Description

Reads certificate and private key from a PKCS12 file.  
Please call PKCS12.Release later to release memory.  
  
This function requires a native path. Use [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md) to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use [FileDialog](component_FileDialog.md) functions.  
For Server be aware that server has limited permissions and may not be able to access all files on a computer.  
### Examples

Read PKCS12 file and shows details:

 Set Variable \[$p12 ; Value:MBS ( "PKCS12.ReadFromFile"; "/Users/cs/Desktop/test.p12"; "test" )\]  
If \[MBS ("IsError")\]  
 Show Custom Dialog \["Error"; $p12 \]  
Else  
 Set Variable \[$cert ; Value:MBS ( "PKCS12.Cert"; $p12 )\]  
 Set Variable \[$pkey ; Value:MBS ( "PKCS12.PKey"; $p12 )\]  
 Set Variable \[$CACount ; Value:MBS ( "PKCS12.CACount"; $p12 )\]  
 Show Custom Dialog \["Certificate"; MBS ( "X509.Description"; $cert )\]  
 Show Custom Dialog \["Private Key"; MBS ( "[PKey.DescriptionPrivateKey](PKeyDescriptionPrivateKey.md)"; $pkey )\]  
 Set Variable \[$r ; Value:MBS ( "[PKey.Release](PKeyRelease.md)"; $pkey )\]  
 Set Variable \[$r ; Value:MBS ( "X509.Release"; $cert )\]  
 Set Variable \[$r ; Value:MBS ( "PKCS12.Release"; $p12 )\]  
End If  
Read sample pfx file:

 Set Variable \[$pkcs12 ; Value: MBS ( "PKCS12.ReadFromFile"; "/Users/cs/Desktop/test\_cert.pfx"; "123456") \]  
### See also

- [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md)
- [PKCS12.CA](PKCS12CA.md)
- [PKCS12.Cert](PKCS12Cert.md)
- [PKCS12.PKey](PKCS12PKey.md)
- [PKCS7.ReadFromFile](PKCS7ReadFromFile.md)
- [PKey.DescriptionPrivateKey](PKeyDescriptionPrivateKey.md)
- [PKey.ReadFromFile](PKeyReadFromFile.md)
- [PKey.Release](PKeyRelease.md)
- [X509.Description](X509Description.md)
- [X509.Release](X509Release.md)

This function checks for a license.

Created 23th December 2016 , last changed 28th February 2023

  
[PKCS12.ReadFromContainer](PKCS12ReadFromContainer.md) - [PKCS12.Release](PKCS12Release.md)

[HTML Version](PKCS12ReadFromFile.shtml)