本文整理汇总了PHP中openssl_csr_export函数的典型用法代码示例。如果您正苦于以下问题:PHP openssl_csr_export函数的具体用法?PHP openssl_csr_export怎么用?PHP openssl_csr_export使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了openssl_csr_export函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __toString
/**
* @return string
*/
public function __toString()
{
$this->generate();
$output = '';
openssl_csr_export($this->request, $output);
return $output;
}
示例2: generate
/**
* {@inheritdoc}
*/
public function generate(KeyPair $keyPair, array $domains)
{
if (!($privateKey = openssl_pkey_get_private($keyPair->getPrivate()))) {
// TODO: Improve error message
throw new AcmeException("Couldn't use private key.");
}
$san = implode(",", array_map(function ($dns) {
return "DNS:{$dns}";
}, $domains));
// http://www.heise.de/netze/rfc/rfcs/rfc7633.shtml
// http://www.heise.de/netze/rfc/rfcs/rfc6066.shtml
$mustStaple = $this->mustStaple ? "tlsfeature = status_request" : "";
$tempFile = tempnam(sys_get_temp_dir(), "acme-openssl-config-");
$tempConf = <<<EOL
[ req ]
distinguished_name = req_distinguished_name
req_extensions = v3_req
{$mustStaple}
[ req_distinguished_name ]
[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = digitalSignature, nonRepudiation
subjectAltName = {$san}
EOL;
(yield \Amp\File\put($tempFile, $tempConf));
$csr = openssl_csr_new(["CN" => reset($domains)], $privateKey, ["digest_alg" => "sha256", "config" => $tempFile]);
(yield \Amp\File\unlink($tempFile));
if (!$csr) {
// TODO: Improve error message
throw new AcmeException("CSR could not be generated.");
}
(yield new CoroutineResult(openssl_csr_export($csr, $csr)));
}
示例3: createNewKeyPair
/**
* Creates a new public/private key pair using PHP OpenSSL extension.
*
* @return \TYPO3\CMS\Rsaauth\Keypair A new key pair or NULL in case of error
* @see tx_rsaauth_abstract_backend::createNewKeyPair()
*/
public function createNewKeyPair()
{
$result = NULL;
$privateKey = @openssl_pkey_new();
if ($privateKey) {
// Create private key as string
$privateKeyStr = '';
openssl_pkey_export($privateKey, $privateKeyStr);
// Prepare public key information
$exportedData = '';
$csr = openssl_csr_new(array(), $privateKey);
openssl_csr_export($csr, $exportedData, FALSE);
// Get public key (in fact modulus) and exponent
$publicKey = $this->extractPublicKeyModulus($exportedData);
$exponent = $this->extractExponent($exportedData);
// Create result object
$result = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Rsaauth\\Keypair');
/** @var $result \TYPO3\CMS\Rsaauth\Keypair */
$result->setExponent($exponent);
$result->setPrivateKey($privateKeyStr);
$result->setPublicKey($publicKey);
// Clean up all resources
openssl_free_key($privateKey);
}
return $result;
}
示例4: createNewKeyPair
/**
* Creates a new key pair for the encryption or gets the existing key pair (if one already has been generated).
*
* There should only be one key pair per request because the second private key would overwrites the first private
* key. So the submitting the form with the first public key would not work anymore.
*
* @return \TYPO3\CMS\Rsaauth\Keypair|NULL a key pair or NULL in case of error
*/
public function createNewKeyPair()
{
/** @var $keyPair \TYPO3\CMS\Rsaauth\Keypair */
$keyPair = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Rsaauth\\Keypair');
if ($keyPair->isReady()) {
return $keyPair;
}
$privateKey = @openssl_pkey_new();
if ($privateKey !== FALSE) {
// Create private key as string
$privateKeyStr = '';
openssl_pkey_export($privateKey, $privateKeyStr);
// Prepare public key information
$exportedData = '';
$csr = openssl_csr_new(array('localityName' => 'foo', 'organizationName' => 'bar'), $privateKey);
openssl_csr_export($csr, $exportedData, FALSE);
// Get public key (in fact modulus) and exponent
$publicKey = $this->extractPublicKeyModulus($exportedData);
$exponent = $this->extractExponent($exportedData);
$keyPair->setExponent($exponent);
$keyPair->setPrivateKey($privateKeyStr);
$keyPair->setPublicKey($publicKey);
// Clean up all resources
openssl_free_key($privateKey);
} else {
$keyPair = NULL;
}
return $keyPair;
}
示例5: run
public function run()
{
if (strrev($this->input['folder']) !== DIRECTORY_SEPARATOR) {
$this->input['folder'] .= DIRECTORY_SEPARATOR;
}
$files = [];
foreach (['pub', 'key', 'crt', 'csr'] as $extension) {
$files[$extension] = sprintf('%s%s%s.%s', $this->input['folder'], $this->input['prefix'], $this->input['hostname'], $extension);
}
foreach ($files as $file) {
if (file_exists($file)) {
throw new RuntimeException(sprintf('File exist: %s', $file));
}
}
$dn = array("countryName" => $this->input['country'], "stateOrProvinceName" => $this->input['state-or-province-name'], "localityName" => $this->input['locality-name'], "organizationName" => $this->input['organization-name'], "organizationalUnitName" => $this->input['organizational-unit-name'], "commonName" => $this->input['common-name'], "emailAddress" => $this->input['email-address']);
// Create the private and public key
$res = openssl_pkey_new(['digest_alg' => $this->input['alg'], 'private_key_bits' => $this->input['bits'], 'private_key_type' => OPENSSL_KEYTYPE_RSA]);
// Generate a certificate signing request
$csr = openssl_csr_new(array_filter($dn), $res);
// Creates a self-signed cert
$sscert = openssl_csr_sign($csr, null, $res, $this->input['days']);
openssl_csr_export($csr, $out);
file_put_contents($files['csr'], $out);
// Export certfile
openssl_x509_export($sscert, $out);
file_put_contents($files['crt'], $out);
// Extract the private key from $res to $privKey
openssl_pkey_export($res, $out);
file_put_contents($files['key'], $out);
// Extract the public key from $res to $pubKey
$out = openssl_pkey_get_details($res);
file_put_contents($files['pub'], $out["key"]);
}
示例6: createNewKeyPair
/**
* Creates a new public/private key pair using PHP OpenSSL extension.
*
* @return tx_rsaauth_keypair A new key pair or null in case of error
* @see tx_rsaauth_abstract_backend::createNewKeyPair()
*/
public function createNewKeyPair()
{
$result = null;
$privateKey = @openssl_pkey_new();
if ($privateKey) {
// Create private key as string
$privateKeyStr = '';
openssl_pkey_export($privateKey, $privateKeyStr);
// Prepare public key information
$exportedData = '';
$csr = openssl_csr_new(array(), $privateKey);
openssl_csr_export($csr, $exportedData, false);
// Get public key (in fact modulus) and exponent
$publicKey = $this->extractPublicKeyModulus($exportedData);
$exponent = $this->extractExponent($exportedData);
// Create result object
$result = t3lib_div::makeInstance('tx_rsaauth_keypair');
/* @var $result tx_rsaauth_keypair */
$result->setExponent($exponent);
$result->setPrivateKey($privateKeyStr);
$result->setPublicKey($publicKey);
// Clean up all resources
openssl_free_key($privateKey);
}
return $result;
}
示例7: getCSRFromFile
private function getCSRFromFile($file)
{
$rsa = $this->getFile($file);
$csr = openssl_csr_new(array(), $rsa);
openssl_csr_export($csr, $csr_out);
return $csr_out;
}
示例8: export
/**
* Export this CSR
*
* @return string CSR
*/
public function export()
{
if (FALSE === openssl_csr_export($this->_res, $out)) {
trigger_error(implode("\n @", OpenSslUtil::getErrors()), E_USER_NOTICE);
throw new XPException('Could not export CSR');
}
return $out;
}
示例9: signCertificateRequest
/**
* Generate a CSR from the given distinguishedName and keyPair.
*
* @param CertificateRequest $certificateRequest
*
* @return string
*/
public function signCertificateRequest(CertificateRequest $certificateRequest)
{
$csrObject = $this->createCsrWithSANsObject($certificateRequest);
if (!$csrObject || !openssl_csr_export($csrObject, $csrExport)) {
throw new CSRSigningException(sprintf('OpenSSL CSR signing failed with error: %s', openssl_error_string()));
}
return $csrExport;
}
示例10: generateKeys
function generateKeys($passphrase)
{
$identity = Zend_Auth::getInstance()->getIdentity();
$dn = array("countryName" => $this->_config->countryName, "stateOrProvinceName" => $this->_config->stateOrProvinceName, "localityName" => $this->_config->localityName, "organizationName" => $this->_config->organizationName, "organizationalUnitName" => $this->_config->organizationUnitName, "commonName" => $identity->firstName . " " . $identity->lastName . "(" . $identity->username . ")", "emailAddress" => $this->_config->emailAddress);
$privkey = openssl_pkey_new();
$csr = openssl_csr_new($dn, $privkey);
$sscert = openssl_csr_sign($csr, null, $privkey, $this->_config->numberOfDays);
openssl_x509_export($sscert, $publickey);
openssl_pkey_export($privkey, $privatekey);
openssl_csr_export($csr, $csrStr);
$this->publicKey = $publickey;
$this->privateKey = $this->_encryptPrivateKey($privatekey, $passphrase);
}
示例11: createKeys
/**
* Generates a new key pair and returns it as an array, which has
* 0 => Public Key
* 1 => Exponent
* 3 => Private Key
*
* @return array
*/
public function createKeys()
{
// Initialize
$keyResource = openssl_pkey_new();
$csr = openssl_csr_new(array(), $keyResource);
// Export the private key
openssl_pkey_export($keyResource, $privateKey);
// Export the public key
openssl_csr_export($csr, $data, FALSE);
preg_match('/Modulus:\\n?(?P<publicKey>[a-f0-9:\\s]+)\\s*Exponent:\\s*(?P<exponent>[0-9]+)/', $data, $matches);
$publicKey = trim(strtoupper(substr(preg_replace('/[\\s\\n\\r:]+/', '', $matches['publicKey']), 2)));
$exponent = (int) $matches['exponent'];
openssl_free_key($keyResource);
return array($publicKey, $exponent, $privateKey);
}
示例12: export
/**
* A method for exporting the certificate.
*
* @param mixed $password
* @return string
*/
public function export($type = 'x509', $password = null)
{
if ($this->signed === false) {
openssl_csr_export($this->csr, $out);
return $out;
} else {
switch ($type) {
case 'x509':
openssl_x509_export($this->csr, $out);
break;
case 'pkcs12':
openssl_pkcs12_export($this->csr, $out, $this->keyPair->privateKey, $password);
break;
}
return $out;
}
}
示例13: gen_new_keypair
function gen_new_keypair($expired = false)
{
$config = array('private_key_bits' => 384, 'digest_alg' => 'sha1', 'private_key_type' => OPENSSL_KEYTYPE_RSA);
$privkey = openssl_pkey_new($config);
$pw = "c0nfusa";
$dn = array("countryName" => 'NO', "localityName" => 'Drammen', "organizationName" => 'Austad IT', "commonName" => 'austad.us', "emailAddress" => 'henrik@austad.us');
$csr = openssl_csr_new($dn, $privkey);
if ($expired) {
$cert = openssl_csr_sign($csr, null, $privkey, -1);
} else {
$cert = openssl_csr_sign($csr, null, $privkey, 14);
}
openssl_pkey_export($privkey, $privkeystr, $pw);
openssl_x509_export($cert, $certstr);
openssl_csr_export($csr, $csrstr);
return array('key' => $privkeystr, 'cert' => $certstr, 'csr' => $csrstr, 'pw' => $pw);
}
示例14: test_openssl_csr_sign
function test_openssl_csr_sign()
{
$dn = array("countryName", "stateOrProvinceName", "localityName", "organizationName", "organizationalUnitName", "commonName", "emailAddress");
$privkeypass = "1234";
$numberofdays = 365;
$privkey = openssl_pkey_new();
VERIFY($privkey != null);
$csr = openssl_csr_new($dn, $privkey);
VERIFY($csr != null);
$scert = openssl_csr_sign($csr, null, $privkey, $numberofdays);
openssl_x509_export($scert, $publickey);
openssl_pkey_export($privkey, $privatekey, $privkeypass);
openssl_csr_export($csr, $csrStr);
VERIFY(strlen($privatekey) > 500);
VERIFY(strlen($publickey) > 800);
VERIFY(strlen($csrStr) > 500);
}
示例15: gen_CSR_PKey
public function gen_CSR_PKey($dn, &$privKey, &$csr_export)
{
$config = array("digest_alg" => "sha1", "private_key_bits" => 2048, "private_key_type" => OPENSSL_KEYTYPE_RSA);
$dn_full = array_merge(array("countryName" => "RU", "stateOrProvinceName" => "Russia", "localityName" => ".", "organizationalUnitName" => "."), $dn);
$res = openssl_pkey_new($config);
$csr_origin = openssl_csr_new($dn_full, $res);
$csr_full = "";
openssl_pkey_export($res, $privKey);
openssl_csr_export($csr_origin, $csr_export);
openssl_csr_export($csr_origin, $csr_full, false);
preg_match('"Signature Algorithm\\: (.*)-----BEGIN"ims', $csr_full, $sign);
$sign = str_replace("\t", "", $sign);
if ($sign) {
$sign = $sign[1];
$a = explode("\n", $sign);
unset($a[0]);
$sign = str_replace(" ", "", trim(join("\n", $a)));
}
return $sign;
}