PHP openssl_pkcs12_export_to_file() Function Last Updated : 28 Jul, 2022 Comments Improve Suggest changes Like Article Like Report The openssl_pkcs12_export_to_file() function is an inbuilt function in PHP which is used to store x509 into a file named by filename in a PKCS#12 file format. PKCS12 is Public-Key Cryptography Standards which defines an archive-file format for storing server certificates. Syntax: bool openssl_pkcs12_export_to_file( mixed $x509, string $filename, mixed $priv_key, string $pass [, array $args ]) Parameters: This function accepts two parameters as mentioned above and described below: $x509: This parameter is a standard defining the format of the public key certificates.$filename: This parameter is the path of the output file.$priv_key: This parameter is used for the private key that matches the dessert "priv_key". The private key is a component of the PKCS # 12 file.$pass: This parameter is used for the encryption password for unlocking the PKCS#12 file.$args: This parameter stands for the arguments and variables which are values representing something else. Return Values: This function returns TRUE on success or FALSE on failure. Below program illustrates the openssl_pkcs12_export_to_file() function in PHP: Program: PHP <?php $dn = array( "countryName" => 'xx', "stateOrProvinceName" => 'uttar prradesh', "localityName" => 'varanasi', "organizationName" => 'geeksforgeeks', "organizationalUnitName" => 'geeks team', "commonName" => 'people', "emailAddress" => '[email protected]' ); $privateKeyPass = 'abcd1234'; $numberOfDays = 108; $privateKey = openssl_pkey_new(); $csr = openssl_csr_new($dn, $privateKey); // Create a csr file, change null // to a filename to save $sscert = openssl_csr_sign($csr, null, $privateKey, $numberOfDays); // On success $publicKey will // hold the PEM content openssl_x509_export($sscert, $publicKey); // Export the privateKey as a PEM content openssl_pkey_export($privateKey, $privateKey, $privateKeyPass); $filename = dirname(__FILE__) . '/certificate.pfx'; // Parses the $privateKey and used // by openssl_pkcs12_export_to_file $key = openssl_pkey_get_private( $privateKey, $privateKeyPass); // Save the pfx file to $filename openssl_pkcs12_export_to_file($sscert, $filename, $key, $privateKeyPass); ?> Output: people Identity: people Verified by: people Expires: Wednesday 16 December 2020 Subject Name C (Country): xx ST (State): uttar pradesh L (Locality): varanasi O (Organization): geeksforgeeks OU (Organizational Unit): geeks team CN (Common Name): people EMAIL (Email Address): [email protected] Issuer Name C (Country): xx ST (State): uttar pradesh L (Locality): varanasi O (Organization): geeksforgeeks OU (Organizational Unit): geeks team CN (Common Name): people EMAIL (Email Address): [email protected] Issued Certificate Version: 3 Serial Number: 00 Not Valid Before: 2020-08-30 Not Valid After: 2020-12-16 Certificate Fingerprints SHA1: 95 D9 8E BB C0 9A 6D 33 C7 98 07 B9 36 F7 12 8E BB 54 4B 50 MD5: 64 7D 63 13 EB 80 55 C2 9D F8 41 DF 0E 7E 75 54 Public Key Info Key Algorithm: RSA Key Parameters: 05 00 Key Size: 2048 Key SHA1 Fingerprint: 25 F6 E2 26 5E 1E 7D B1 10 82 02 9D F3 05 1A 72 3B C4 9B 7C Public Key: 30 82 01 0A 02 82 01 01 00 C4 CC 93 62 F9 D2 C9 39 5F F1 15 13 A2 2D 34 93 4C AD 45 E8 7E AE CE 24 C6 FA 2B 99 6B FE B7 F7 30 D6 95 DA 3A 1C FB 1E BC 8F A6 C6 9D A4 03 3E 46 16 56 AB A5 78 32 2A C3 D3 FA 79 C 3 5B 38 02 07 22 E6 6C 51 C9 B9 5C 44 AE 65 D3 0F ED F9 80 F4 1D 01 66 11 8A E1 78 55 DA C2 2E 72 3E 8E D3 D2 CB 4C 40 0B 0E 55 BD EF 26 A1 21 E7 62 43 39 4B EF EE EB 85 40 11 E3 A9 44 D8 B2 FB 1B 46 13 1E 25 A0 8E 9D F3 BA 1B F7 80 A8 1A 87 97 20 CE C0 1E 45 11 9A 94 F0 68 71 BA 7B 86 5F A8 55 69 E8 D4 C1 D0 E0 75 72 7E 3E A1 6D B4 8B 2A 8C D2 69 2D E2 F8 F4 09 8A 8B 42 1E 1B C1 93 66 06 A8 AD FF 31 3F E5 D9 10 07 A8 AC 7E B9 69 9E CA 67 1B 83 99 5E 3E 58 26 28 60 A5 BC 45 92 4A C4 A3 16 6B 33 62 E4 AA 77 FA 28 90 01 40 2F 0E 7D D8 B7 3C E9 A6 B3 25 DB 07 E1 0F D6 CE 0E B4 42 B3 02 03 01 00 01 Subject Key Identifier Key Identifier: 03 D6 83 8F E6 36 C2 08 39 F5 2B 0C D2 FA 17 3C 21 32 C6 EF Critical: No Extension Identifier: 2.5.29.35 Value: 30 16 80 14 03 D6 83 8F E6 36 C2 08 39 F5 2B 0C D2 FA 17 3C 21 32 C6 EF Critical: No Basic Constraints Certificate Authority: Yes Max Path Length: Unlimited Critical: Yes Signature Signature Algorithm: SHA1 with RSA Signature Parameters: 05 00 Signature: B2 D0 04 4E 62 8F 8F 30 7D 19 62 6E AB 6F AC 01 0A 2C 11 A6 19 09 73 21 35 74 89 3A ED CB 91 2E E4 50 77 CC 1A E9 7E 43 B5 E6 83 6F 3E EC 0F 5A 91 EB C4 99 37 08 76 12 2D 26 95 AD F6 7B A7 3F 42 CE 4F 5E 1A C6 DD 71 66 73 30 2A 87 FB CC BE 7C B9 82 AA 09 AE 88 EC D4 C4 78 20 6B FA 08 B4 65 C3 D1 1D BB 78 B9 4B B2 E7 00 3C 62 4B EF 74 4B 2D BE 15 BD E1 A0 DE 9B 82 2B 24 F8 01 CD 90 30 C9 2F 87 6C B5 85 54 84 F3 7F A4 5C 3F 74 22 B1 3E 60 DB 81 4C C1 23 52 00 FD 4D 53 F3 02 17 EE AE E8 1F 24 02 81 DF B7 49 EA 8B 93 41 78 DA 4D 9E 34 B2 F4 E0 68 69 AA A9 0E ED 17 04 EA 6F FD C2 27 96 BC 1C A2 53 E8 80 AE 51 D1 F2 00 34 44 A0 5E AE F4 35 E4 CB 1D 61 F8 CB 25 B4 28 7C 7A 5C 82 8A 08 7B A2 DB E9 BA 67 CC FB C6 34 D3 D5 2D 8C C6 12 7F 5C BF 18 FA 7D CA 40 67 17 15 certificate.pfx Private RSA Key Strength: 2048 bits Algorithm: RSA Size: 2048 Fingerprints SHA1: 25 F6 E2 26 5E 1E 7D B1 10 82 02 9D F3 05 1A 72 3B C4 9B 7C SHA256: D8 63 1A 26 8D AE 7D 56 67 48 6E AA D3 8D B1 D7 8F 4A C2 C4 D6 D8 58 BA 32 53 AB D1 93 72 40 6F Reference: https://www.php.net/manual/en/function.openssl-pkcs12-export-to-file.php Comment More infoAdvertise with us Next Article PHP Syntax S shubham_singh Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP Tutorial PHP is a popular, open-source scripting language mainly used in web development. It runs on the server side and generates dynamic content that is displayed on a web application. PHP is easy to embed in HTML, and it allows developers to create interactive web pages and handle tasks like database mana 9 min read BasicsPHP SyntaxPHP, a powerful server-side scripting language used in web development. Itâs simplicity and ease of use makes it an ideal choice for beginners and experienced developers. This article provides an overview of PHP syntax. PHP scripts can be written anywhere in the document within PHP tags along with n 4 min read PHP VariablesA variable in PHP is a container used to store data such as numbers, strings, arrays, or objects. The value stored in a variable can be changed or updated during the execution of the script.All variable names start with a dollar sign ($).Variables can store different data types, like integers, strin 5 min read PHP | FunctionsA function in PHP is a self-contained block of code that performs a specific task. It can accept inputs (parameters), execute a set of statements, and optionally return a value. PHP functions allow code reusability by encapsulating a block of code to perform specific tasks.Functions can accept param 8 min read PHP LoopsIn PHP, Loops are used to repeat a block of code multiple times based on a given condition. PHP provides several types of loops to handle different scenarios, including while loops, for loops, do...while loops, and foreach loops. In this article, we will discuss the different types of loops in PHP, 4 min read ArrayPHP ArraysArrays are one of the most important data structures in PHP. They allow you to store multiple values in a single variable. PHP arrays can hold values of different types, such as strings, numbers, or even other arrays. Understanding how to use arrays in PHP is important for working with data efficien 5 min read PHP Associative ArraysAn associative array in PHP is a special array where each item has a name or label instead of just a number. Usually, arrays use numbers to find things. For example, the first item is at position 0, the second is 1, and so on. But in an associative array, we use words or names to find things. These 4 min read Multidimensional arrays in PHPMulti-dimensional arrays in PHP are arrays that store other arrays as their elements. Each dimension adds complexity, requiring multiple indices to access elements. Common forms include two-dimensional arrays (like tables) and three-dimensional arrays, useful for organizing complex, structured data. 5 min read Sorting Arrays in PHPSorting arrays is one of the most common operation in programming, and PHP provides a several functions to handle array sorting. Sorting arrays in PHP can be done by values or keys, in ascending or descending order. PHP also allows you to create custom sorting functions.Table of ContentSort Array in 4 min read OOPs & InterfacesPHP ClassesA class defines the structure of an object. It contains properties (variables) and methods (functions). These properties and methods define the behavior and characteristics of an object created from the class.Syntax:<?phpclass Camera { // code goes here...}?>Now, let us understand with the hel 2 min read PHP | Constructors and DestructorsIn PHP, constructors and destructors are special methods that are used in object-oriented programming (OOP). They help initialize objects when they are created and clean up resources when the object is no longer needed. These methods are part of the class lifecycle.In this article, we will discuss w 5 min read PHP Access ModifiersIn object-oriented programming, access specifiers are also known as access modifiers. These specifiers control how and where the properties or methods of a class can be accessed, either from inside the class, from a subclass, or from outside the class. PHP supports three primary access specifiers: p 4 min read Multiple Inheritance in PHPMultiple Inheritance is the property of the Object Oriented Programming languages in which child class or sub class can inherit the properties of the multiple parent classes or super classes. PHP doesn't support multiple inheritance but by using Interfaces in PHP or using Traits in PHP instead of cl 4 min read MySQL DatabasePHP | MySQL Database IntroductionWhat is MySQL? MySQL is an open-source relational database management system (RDBMS). It is the most popular database system used with PHP. MySQL is developed, distributed, and supported by Oracle Corporation. The data in a MySQL database are stored in tables which consists of columns and rows.MySQL 4 min read PHP Database connectionThe collection of related data is called a database. XAMPP stands for cross-platform, Apache, MySQL, PHP, and Perl. It is among the simple light-weight local servers for website development. Requirements: XAMPP web server procedure: Start XAMPP server by starting Apache and MySQL. Write PHP script f 2 min read PHP | MySQL ( Creating Database )What is a database? Database is a collection of inter-related data which helps in efficient retrieval, insertion and deletion of data from database and organizes the data in the form of tables, views, schemas, reports etc. For Example, university database organizes the data about students, faculty, 3 min read PHP | MySQL ( Creating Table )What is a table? In relational databases, and flat file databases, a table is a set of data elements using a model of vertical columns and horizontal rows, the cell being the unit where a row and column intersect. A table has a specified number of columns, but can have any number of rows. Creating a 3 min read PHP AdvancePHP SuperglobalsPHP superglobals are predefined variables that are globally available in all scopes. They are used to handle different types of data, such as input data, server data, session data, and more. These superglobal arrays allow developers to easily work with these global data structures without the need t 6 min read PHP | Regular ExpressionsRegular expressions commonly known as a regex (regexes) are a sequence of characters describing a special search pattern in the form of text string. They are basically used in programming world algorithms for matching some loosely defined patterns to achieve some relevant tasks. Some times regexes a 12 min read PHP Form HandlingForm handling is the process of collecting and processing information that users submit through HTML forms. In PHP, we use special tools called $_POST and $_GET to gather the data from the form. Which tool to use depends on how the form sends the dataâeither through the POST method (more secure, hid 4 min read PHP File HandlingIn PHP, File handling is the process of interacting with files on the server, such as reading files, writing to a file, creating new files, or deleting existing ones. File handling is essential for applications that require the storage and retrieval of data, such as logging systems, user-generated c 4 min read PHP | Uploading FileHave you ever wondered how websites build their system of file uploading in PHP? Here we will come to know about the file uploading process. A question which you can come up with - 'Are we able to upload any kind of file with this system?'. The answer is yes, we can upload files with different types 3 min read PHP CookiesA cookie is a small text file that is stored in the user's browser. Cookies are used to store information that can be retrieved later, making them ideal for scenarios where you need to remember user preferences, such as:User login status (keeping users logged in between sessions)Language preferences 9 min read PHP | SessionsA session in PHP is a mechanism that allows data to be stored and accessed across multiple pages on a website. When a user visits a website, PHP creates a unique session ID for that user. This session ID is then stored as a cookie in the user's browser (by default) or passed via the URL. The session 7 min read Like