Advertisement
Guest User

Untitled

a guest
Feb 9th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <?php
  2. include('File/X509.php');
  3. include('Crypt/RSA.php');
  4.  
  5. // create private key / x.509 cert for stunnel / website
  6. $privKey = new Crypt_RSA();
  7. extract($privKey->createKey());
  8. $privKey->loadKey($privatekey);
  9.  
  10. $pubKey = new Crypt_RSA();
  11. $pubKey->loadKey($publickey);
  12. $pubKey->setPublicKey();
  13.  
  14. $subject = new File_X509();
  15. $subject->setDNProp('id-at-organizationName', 'phpseclib demo cert');
  16. $subject->setPublicKey($pubKey);
  17.  
  18. $issuer = new File_X509();
  19. $issuer->setPrivateKey($privKey);
  20. $issuer->setDN($subject->getDN());
  21.  
  22. $x509 = new File_X509();
  23. //$x509->setStartDate('-1 month'); // default: now
  24. //$x509->setEndDate('+1 year'); // default: +1 year
  25.  
  26. $result = $x509->sign($issuer, $subject);
  27. $cert = $x509->saveX509($result, 1);
  28. $asn1 = new File_ASN1();
  29.  
  30. $result['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey'] = new File_ASN1_Element($asn1->encodeDER(base64_encode($cert), array('type' => FILE_ASN1_TYPE_BIT_STRING)));
  31.  
  32. echo "the stunnel.pem contents are as follows:\r\n\r\n";
  33. echo $privKey->getPrivateKey();
  34. echo "\r\n";
  35. echo $x509->saveX509($result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement