Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('File/X509.php');
- include('Crypt/RSA.php');
- // create private key / x.509 cert for stunnel / website
- $privKey = new Crypt_RSA();
- extract($privKey->createKey());
- $privKey->loadKey($privatekey);
- $pubKey = new Crypt_RSA();
- $pubKey->loadKey($publickey);
- $pubKey->setPublicKey();
- $subject = new File_X509();
- $subject->setDNProp('id-at-organizationName', 'phpseclib demo cert');
- $subject->setPublicKey($pubKey);
- $issuer = new File_X509();
- $issuer->setPrivateKey($privKey);
- $issuer->setDN($subject->getDN());
- $x509 = new File_X509();
- //$x509->setStartDate('-1 month'); // default: now
- //$x509->setEndDate('+1 year'); // default: +1 year
- $result = $x509->sign($issuer, $subject);
- $cert = $x509->saveX509($result, 1);
- $asn1 = new File_ASN1();
- $result['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey'] = new File_ASN1_Element($asn1->encodeDER(base64_encode($cert), array('type' => FILE_ASN1_TYPE_BIT_STRING)));
- echo "the stunnel.pem contents are as follows:\r\n\r\n";
- echo $privKey->getPrivateKey();
- echo "\r\n";
- echo $x509->saveX509($result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement