本文整理汇总了PHP中openssl_public_decrypt函数的典型用法代码示例。如果您正苦于以下问题:PHP openssl_public_decrypt函数的具体用法?PHP openssl_public_decrypt怎么用?PHP openssl_public_decrypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了openssl_public_decrypt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decryptPublic
function decryptPublic($path, $cText)
{
$fcontents = file_get_contents($path);
$publicKey = openssl_pkey_get_public($fcontents);
openssl_public_decrypt($cText, $decrypted, $publicKey);
return $decrypted;
}
示例2: decrypt
/**
* Decrypts $data using this public key.
* @param mixed $data
* @return string
* @throws DecryptionFailedException
*/
public function decrypt($data)
{
if (!openssl_public_decrypt($data, $decrypted, $this->keyResource)) {
throw new DecryptionFailedException('Failed decrypting the data with this public key.');
}
return $decrypted;
}
示例3: rsaPublicDecrypt
/**
* 通过公钥解密 私钥加密后的内容
*
* @param string $encryptedStr 私钥加密后的字符串
*
* @return string
*/
public static function rsaPublicDecrypt($encryptedStr)
{
$retData = '';
$resourceId = self::getResourceId(self::TYPE_PUBLIC_KEY);
openssl_public_decrypt(base64_decode($encryptedStr), $retData, $resourceId);
return $retData;
}
示例4: check
/**
* Método que verifica el código de autorización de folios
* @return =true si está ok el XML cargado
* @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
* @version 2015-10-30
*/
public function check()
{
// validar firma del SII sobre los folios
$firma = $this->getFirma();
$idk = $this->getIDK();
if (!$firma or !$idk) {
return false;
}
$pub_key = \sasco\LibreDTE\Sii::cert($idk);
if (!$pub_key or openssl_verify($this->xml->getFlattened('/AUTORIZACION/CAF/DA'), base64_decode($firma), $pub_key) !== 1) {
\sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::FOLIOS_ERROR_FIRMA, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::FOLIOS_ERROR_FIRMA));
return false;
}
// validar clave privada y pública proporcionada por el SII
$private_key = $this->getPrivateKey();
if (!$private_key) {
return false;
}
$plain = md5(date('U'));
if (!openssl_private_encrypt($plain, $crypt, $private_key)) {
\sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::FOLIOS_ERROR_ENCRIPTAR, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::FOLIOS_ERROR_ENCRIPTAR));
return false;
}
$public_key = $this->getPublicKey();
if (!$public_key) {
return false;
}
if (!openssl_public_decrypt($crypt, $plain_firmado, $public_key)) {
\sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::FOLIOS_ERROR_DESENCRIPTAR, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::FOLIOS_ERROR_DESENCRIPTAR));
return false;
}
return $plain === $plain_firmado;
}
示例5: publicKeyDecrypt
function publicKeyDecrypt($publicKey, $content)
{
$pKey = openssl_pkey_get_public($publicKey);
$decrypted = "";
openssl_public_decrypt($content, $decrypted, $pKey);
return $decrypted;
}
示例6: check_license
public static function check_license($license)
{
$signature = $license['Signature'];
unset($license['Signature']);
uksort($license, "strcasecmp");
$total = '';
foreach ($license as $value) {
$total .= $value;
}
$key_raw = <<<EOD
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCtl7Dgf4x0fi0lXfws7Cq/lk0d
TIEXnCu8PBMep0mtRia9WEJ8N53d+8gbuAcMzb4sW6MVOzTEKYrmtq/DTbiaXKiJ
o6osz5KgBjbcGrCzKKvk8uQuTZWusqp69LQfTYSwxwJIp45kl0g8yalewGUtpYuu
yWXBBsw7Z909BpTLBQIDAAAD
-----END PUBLIC KEY-----
EOD;
$key = openssl_get_publickey($key_raw);
openssl_public_decrypt(base64_decode($signature), $checkDigest, $key);
$digest = sha1($total, true);
if ($digest === $checkDigest) {
return true;
}
return false;
}
示例7: decrypt
/**
* Decrypt data using this public key. Only data encrypted with
* the private key matching this key will be decryptable.
*
* @param string data
* @return string
* @throws security.crypto.CryptoException if the operation fails
*/
public function decrypt($data)
{
if (false === openssl_public_decrypt($data, $decrypted, $this->_hdl)) {
throw new CryptoException('Could not decrypt data', OpenSslUtil::getErrors());
}
return $decrypted;
}
示例8: dec_pub
function dec_pub($dat)
{
list($cry,$str) = array_map('base64_decode',explode(':',$dat));
$res = openssl_get_publickey($this->pub);
openssl_public_decrypt($cry,$key,$res);
$ret = $this->dec_sym($key,$str);
return trim($ret);
}
示例9: decrypt
public function decrypt($data, $pubkey)
{
$rs = '';
if (@openssl_public_decrypt($data, $rs, $pubkey) === FALSE) {
return NULL;
}
return $rs;
}
示例10: decrypt
/**
* @param string $encrypted
*
* @return string
*/
public function decrypt(string $encrypted) : string
{
$status = openssl_public_decrypt($encrypted, $decrypted, $this);
if (!$status) {
throw new RuntimeException('Decrypt failed');
}
return $decrypted;
}
示例11: decrypt1
public function decrypt1($data)
{
if (openssl_public_decrypt(base64_decode($data), $decrypted, $this->pubkey)) {
$data = $decrypted;
} else {
$data = '';
}
return $data;
}
示例12: verifyAesKeyFileEncrypted
function verifyAesKeyFileEncrypted()
{
$pubk = $this->readIrsPublicKey(true);
$decrypted = "";
if (!openssl_public_decrypt($this->aesEncrypted, $decrypted, $pubk)) {
throw new \Exception("Failed to decrypt aes key for verification purposes");
}
return $decrypted == $this->am->getAesIv();
}
示例13: publicDecrypt
public static function publicDecrypt($pubKey, $data)
{
if (!strstr($pubKey, 'BEGIN PUBLIC KEY')) {
$pubKey = self::lengthenPublicKey($pubKey);
}
$key_resource = openssl_get_publickey($pubKey);
openssl_public_decrypt(base64_decode($data), $cleartext, $key_resource);
return $cleartext;
}
示例14: decryptByPublicKey
public static function decryptByPublicKey($data)
{
$pu_key = openssl_pkey_get_public(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/system/modules/pay/lib/cbjpay/config/wy_rsa_public_ley.pem'));
//这个函数可用来判断公钥是否是可用的,可用返回资源id Resource id
$decrypted = "";
$data = base64_decode($data);
openssl_public_decrypt($data, $decrypted, $pu_key);
//公钥解密
return $decrypted;
}
示例15: decrypt
/**
* Decrypts the given data.
*
* @param string $encryptedData The data to decrypt.
* @param int $padding The padding to use for decryption.
* @return string Returns the decrypted data.
* @since 0.3
*/
public function decrypt(string $encryptedData, int $padding = OPENSSL_PKCS1_PADDING) : string
{
OpenSSL::resetErrors();
if (openssl_public_decrypt($encryptedData, $decrypted, $this->resource, $padding) === false) {
// @codeCoverageIgnoreStart
throw new OpenSSLException(OpenSSL::getErrors(), 'Could not decrypt the given data with this public key.');
// @codeCoverageIgnoreEnd
}
return $decrypted;
}