本文整理汇总了PHP中openssl_pkey_get_details函数的典型用法代码示例。如果您正苦于以下问题:PHP openssl_pkey_get_details函数的具体用法?PHP openssl_pkey_get_details怎么用?PHP openssl_pkey_get_details使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了openssl_pkey_get_details函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadPEM
/**
* @param $data
*
* @throws \Exception
* @throws \FG\ASN1\Exception\ParserException
*
* @return array
*/
private function loadPEM($data)
{
$res = openssl_pkey_get_private($data);
if (false === $res) {
$res = openssl_pkey_get_public($data);
}
if (false === $res) {
throw new \Exception('Unable to load the key');
}
$details = openssl_pkey_get_details($res);
if (!array_key_exists('rsa', $details)) {
throw new \Exception('Unable to load the key');
}
foreach ($details['rsa'] as $key => $value) {
$value = Base64Url::encode($value);
if ($key === 'dmp1') {
$this->dp = $value;
} elseif ($key === 'dmq1') {
$this->dq = $value;
} elseif ($key === 'iqmp') {
$this->qi = $value;
} else {
$this->{$key} = $value;
}
}
}
示例2: EncryptStringRSA
/**
* @param string $sString
* @param string $sKey = ''
*
* @return string|false
*/
public static function EncryptStringRSA($sString, $sKey = '')
{
$sResult = '';
$sKey = \md5($sKey);
$sPrivateKey = \RainLoop\Utils::RsaPrivateKey();
if (!empty($sPrivateKey)) {
$oPrivKey = \openssl_pkey_get_private($sPrivateKey);
$oKeyDetails = \openssl_pkey_get_details($oPrivKey);
if (!empty($oKeyDetails['key']) && !empty($oKeyDetails['bits'])) {
$oPubKey = \openssl_pkey_get_public($oKeyDetails['key']);
$iC = $oKeyDetails['bits'] / 8 - 15;
$aString = \str_split($sString, $iC);
foreach ($aString as $iIndex => $sLine) {
$sEncrypted = '';
\openssl_public_encrypt($sLine, $sEncrypted, $oPubKey);
$aString[$iIndex] = $sEncrypted;
}
$aString[] = $sKey;
$sResult = @\serialize($aString);
\openssl_free_key($oPubKey);
}
\openssl_free_key($oPrivKey);
}
return $sResult;
}
示例3: 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"]);
}
示例4: fetchPublicKey
/**
* Fetches public key from the remote certificate
*
* @param $url
* @return string|false
*/
protected function fetchPublicKey($url)
{
$cache = \Yii::$app->cache;
$cacheKey = 'paypal-public-key-' . md5($url);
$publicKey = $cache->get($cacheKey);
if ($publicKey) {
return $publicKey;
}
// trying to fetch certificate
$cert = @file_get_contents($url);
if (!$cert) {
return false;
}
$key = openssl_pkey_get_public($cert);
if (!$key) {
return false;
}
$keyData = openssl_pkey_get_details($key);
$result = ArrayHelper::getValue($keyData, 'key', false);
if (!$result) {
return false;
}
$cache->add($cacheKey, $result);
return $result;
}
示例5: getPublicKeyShouldReturnAValidResource
/**
* @test
*
* @uses Lcobucci\JWT\RsaKeys
*
* @covers Lcobucci\JWT\Signer\Keychain::getPublicKey
*/
public function getPublicKeyShouldReturnAValidResource()
{
$keychain = new Keychain();
$publicKey = $keychain->getPublicKey($this->publicRsaContent());
$this->assertInternalType('resource', $publicKey);
$this->assertEquals(openssl_pkey_get_details($publicKey), openssl_pkey_get_details($this->publicRsa()));
}
示例6: setUpBeforeClass
public static function setUpBeforeClass()
{
$keyResource = openssl_pkey_new();
openssl_pkey_export($keyResource, $privateKey);
self::$publicKey = openssl_pkey_get_details($keyResource)['key'];
self::$privateKey = $privateKey;
}
示例7: get_keys
static public function get_keys($login,$full_name) {
$CA_CERT = base_url()."data/key/CA_DOC.csr";
$CA_KEY = base_url()."data/key/CA_DOC_priv.key";
$config = array(
"private_key_type"=>OPENSSL_KEYTYPE_RSA,
"private_key_bits"=>512
);
$res = openssl_pkey_new($config);
$privKey = '';
openssl_pkey_export($res,$privKey);
$arr = array(
"organizationName" => "Фізична особа",
"organizationalUnitName" => "Фізична особа",
"commonName" => $full_name,
"UID" => $login,
"countryName" => "UA"
);
$csr = openssl_csr_new($arr,$privKey);
$cert = openssl_csr_sign($csr,file_get_contents($CA_CERT),file_get_contents($CA_KEY),730);
openssl_x509_export($cert,$str_cert);
$public_key = openssl_pkey_get_public($str_cert);
$public_key_details = openssl_pkey_get_details($public_key);
$public_key_string = $public_key_details['key'];
return array('private'=>$privKey,'cert'=>$str_cert,'public'=>$public_key_string);
}
示例8: testCreate
public function testCreate()
{
$container = ContainerLoader::buildTestContainer();
$em = $container->get('doctrine.orm.entity_manager');
$client = new Client();
$client->setClientId($token = 'test-client-' . rand());
$client->setClientSecret('very-secure');
$client->setRedirectUri(array('http://brentertainment.com'));
$em->persist($client);
$em->flush();
$public_key = new ClientPublicKey();
$public_key->setClient($client);
// create and set the public key
$res = openssl_pkey_new();
// Extract the public key from $res to $pubKey
$pubKeyDetails = openssl_pkey_get_details($res);
$pubKey = $pubKeyDetails['key'];
$public_key->setPublicKey($pubKey);
$em->persist($public_key);
$em->flush();
// test direct access
$stored = $em->find('OAuth2\\ServerBundle\\Entity\\ClientPublicKey', array('client_id' => $client->getClientId()));
$this->assertNotNull($stored);
$this->assertEquals($pubKey, $stored->getPublicKey());
}
示例9: webid_claim
function webid_claim()
{
$r = array('uri' => array());
if (isset($_SERVER['SSL_CLIENT_CERT'])) {
$pem = $_SERVER['SSL_CLIENT_CERT'];
if ($pem) {
$x509 = openssl_x509_read($pem);
$pubKey = openssl_pkey_get_public($x509);
$keyData = openssl_pkey_get_details($pubKey);
if (isset($keyData['rsa'])) {
if (isset($keyData['rsa']['n'])) {
$r['m'] = strtolower(array_pop(unpack("H*", $keyData['rsa']['n'])));
}
if (isset($keyData['rsa']['e'])) {
$r['e'] = hexdec(array_shift(unpack("H*", $keyData['rsa']['e'])));
}
}
$d = openssl_x509_parse($x509);
if (isset($d['extensions']) && isset($d['extensions']['subjectAltName'])) {
foreach (explode(', ', $d['extensions']['subjectAltName']) as $elt) {
if (substr($elt, 0, 4) == 'URI:') {
$r['uri'][] = substr($elt, 4);
}
}
}
}
}
return $r;
}
示例10: build
public function build($filename, $stub)
{
if (file_exists($filename)) {
unlink($filename);
}
$phar = new \Phar($filename, 0, $this->aliasName != '' ? $this->aliasName : basename($filename));
$phar->startBuffering();
$phar->setStub($stub);
if ($this->key !== NULL) {
$privateKey = '';
openssl_pkey_export($this->key, $privateKey);
$phar->setSignatureAlgorithm(\Phar::OPENSSL, $privateKey);
$keyDetails = openssl_pkey_get_details($this->key);
file_put_contents($filename . '.pubkey', $keyDetails['key']);
} else {
$phar->setSignatureAlgorithm($this->selectSignatureType($phar));
}
$basedir = $this->basedir ? $this->basedir : $this->directories[0];
foreach ($this->directories as $directory) {
$phar->buildFromIterator($this->scanner->__invoke($directory), $basedir);
}
if ($this->compression !== \Phar::NONE) {
$phar->compressFiles($this->compression);
}
$phar->stopBuffering();
}
示例11: generateKeys
/**
* Generate public and private key
* @param array $options
*/
public function generateKeys(array $options = self::DEFAULT_PUBLIC_KEY_OPTIONS)
{
$keys = openssl_pkey_new($options);
$this->publicKey = openssl_pkey_get_details($keys)["key"];
openssl_pkey_export($keys, $this->privateKey);
openssl_pkey_free($keys);
}
示例12: parse
/**
* Parse the key.
*
* @param Key $key
*
* @return ParsedKey
*/
public function parse(Key $key)
{
try {
$resource = $key->getResource();
} catch (KeyFormatException $e) {
throw new KeyParsingException('Fail to load resource for key', 0, $e);
}
$rawData = openssl_pkey_get_details($resource);
if (!is_array($rawData)) {
throw new KeyParsingException(sprintf('Fail to parse key with error: %s', openssl_error_string()));
}
foreach (['type', 'key', 'bits'] as $requiredKey) {
if (!isset($rawData[$requiredKey])) {
throw new KeyParsingException(sprintf('Missing expected key "%s" in OpenSSL key', $requiredKey));
}
}
$details = [];
if ($rawData['type'] === OPENSSL_KEYTYPE_RSA) {
$details = $rawData['rsa'];
} elseif ($rawData['type'] === OPENSSL_KEYTYPE_DSA) {
$details = $rawData['dsa'];
} elseif ($rawData['type'] === OPENSSL_KEYTYPE_DH) {
$details = $rawData['dh'];
}
return new ParsedKey($key, $rawData['key'], $rawData['bits'], $rawData['type'], $details);
}
示例13: t2
function t2()
{
$config = array("digest_alg" => "sha256", "private_key_bits" => 2048, "encrypt_key" => 1, "encrypt_key_cipher" => OPENSSL_CIPHER_AES_256_CBC);
// Create the keypair
$res = openssl_pkey_new($config);
var_dump($res);
// Get private key
openssl_pkey_export($res, $privkey, 'libo', $config);
// Get public key
$publickey = openssl_pkey_get_details($res);
$publickey = $publickey["key"];
echo "Private Key:\n{$privkey}\n\nPublic Key:\n{$publickey}\n\n";
$cleartext = '1234 5678 9012 3456';
echo "Clear text:\n{$cleartext}\n\n";
openssl_public_encrypt($cleartext, $crypttext, $publickey);
echo "Crypt text:\n" . base64_encode($crypttext) . "\n";
$priv = openssl_pkey_get_private($privkey, "libo");
var_dump($priv);
if (!$priv) {
echo "\nGet private key fail!\n";
exit(1);
}
openssl_private_decrypt($crypttext, $decrypted, $priv);
echo "\nDecrypted text:\n{$decrypted}\n\n";
}
示例14: getPublicKey
/**
* return PublicKey
*/
public function getPublicKey()
{
$res = \openssl_pkey_get_private($this->keyMaterial);
$pubkey = \openssl_pkey_get_details($res);
$public = \rtrim(\str_replace("\n", "\r\n", $pubkey['key']), "\r\n");
return new PublicKey($public);
}
示例15: generate
/**
* Generates a new key pair with the given length in bits.
*
* @api
* @param int $bits length of the key
* @return KeyPair generated key pair
*/
public function generate($bits = 2048)
{
if (!is_int($bits)) {
throw new \InvalidArgumentException(sprintf("\$bits must be of type int, %s given", gettype($bits)));
}
if ($bits < 2048) {
throw new \InvalidArgumentException("Keys with fewer than 2048 bits are not allowed!");
}
$configFile = $defaultConfigFile = __DIR__ . "/../res/openssl.cnf";
if (class_exists("Phar") && !empty(Phar::running(true))) {
$configContent = file_get_contents($configFile);
$configFile = tempnam(sys_get_temp_dir(), "acme_openssl_");
file_put_contents($configFile, $configContent);
register_shutdown_function(function () use($configFile) {
@unlink($configFile);
});
}
$res = openssl_pkey_new(["private_key_type" => OPENSSL_KEYTYPE_RSA, "private_key_bits" => $bits, "config" => $configFile]);
$success = openssl_pkey_export($res, $privateKey, null, ["config" => $configFile]);
if ($configFile !== $defaultConfigFile) {
@unlink($configFile);
}
if (!$success) {
openssl_pkey_free($res);
throw new \RuntimeException("Key export failed!");
}
$publicKey = openssl_pkey_get_details($res)["key"];
openssl_pkey_free($res);
// clear error buffer, because of minimalistic openssl.cnf
while (openssl_error_string() !== false) {
}
return new KeyPair($privateKey, $publicKey);
}