Advertisement
Guest User

Untitled

a guest
Feb 9th, 2015
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 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. $decoded = $asn1->decodeBER($cert);
  30.  
  31. $subject = substr($cert, $decoded[0]['content'][0]['start'], $decoded[0]['content'][0]['length']);
  32. $result['tbsCertificate'] = new File_ASN1_Element($subject . 'zzzzz');
  33.  
  34. echo "the stunnel.pem contents are as follows:\r\n\r\n";
  35. echo $privKey->getPrivateKey();
  36. echo "\r\n";
  37. echo $x509->saveX509($result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement