本文整理汇总了PHP中openssl_private_encrypt函数的典型用法代码示例。如果您正苦于以下问题:PHP openssl_private_encrypt函数的具体用法?PHP openssl_private_encrypt怎么用?PHP openssl_private_encrypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了openssl_private_encrypt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rsaPrivateEncrypt
/**
* 私钥加密
*
* @param $dataStr
*
* @return string
*/
public static function rsaPrivateEncrypt($dataStr)
{
$retData = '';
$resourceId = self::getResourceId(self::TYPE_PRIVATE_KEY);
openssl_private_encrypt($dataStr, $retData, $resourceId);
$retData = base64_encode($retData);
return $retData;
}
示例2: encryptPrivate
function encryptPrivate($path, $plainText)
{
$fcontents = file_get_contents($path);
$privateKey = openssl_pkey_get_private($fcontents, "symelosh");
openssl_private_encrypt($plainText, $encrypted, $privateKey);
return $encrypted;
}
示例3: text_enc
function text_enc($str,$key) {
$fpr = fopen($key,"r");
$pr_key = fread($fpr,1024);
fclose($fpr);
openssl_private_encrypt($str,$result,$pr_key);
return $result;
}
示例4: privateKeyEncrypt
function privateKeyEncrypt($privateKey, $content)
{
$piKey = openssl_pkey_get_private($privateKey);
$encrypted = "";
openssl_private_encrypt($content, $encrypted, $piKey);
return base64_encode($encrypted);
}
示例5: encrypt
/**
* Encrypt data using this public key. Data will be decryptable
* only with the matching private key.
*
* This method can only encrypt short data (= shorter than the key,
* see the PHP manual). To encrypt larger values, use the seal()
* method.
*
* @see php://openssl_private_encrypt
* @param string data
* @return string
* @throws security.crypto.CryptoException if the operation fails
*/
public function encrypt($data)
{
if (false === openssl_private_encrypt($data, $crypted, $this->_hdl)) {
throw new CryptoException('Could not decrypt data', OpenSslUtil::getErrors());
}
return $crypted;
}
示例6: privEncrypt
/**
* 私钥加密
* @param [type] $data [description]
* @return [type] [description]
*/
public static function privEncrypt($data)
{
if (!is_string($data)) {
return null;
}
return openssl_private_encrypt($data, $encrypted, self::getPrivateKey()) ? base64_encode($encrypted) : null;
}
示例7: 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;
}
示例8: enc_pri
function enc_pri($str)
{
$key = uniqid();
$res = openssl_get_privatekey($this->pri,$this->pra);
openssl_private_encrypt($key,$cry,$res);
$ret = $this->enc_sym($key,$str);
return base64_encode($cry).':'.base64_encode($ret);
}
示例9: encrypt
/**
* Encrypt the given text with the private key
*
* @param KeyPair $key
* @param string $plainText
* @throws EncryptionException
* @return string
*/
public function encrypt(KeyPair $key, $plainText)
{
$success = openssl_private_encrypt($plainText, $result, $key->getPrivateKey());
if ($success !== TRUE) {
throw new EncryptionException('Encryption failed');
}
return $result;
}
示例10: encrypt
public function encrypt($data, $prikey)
{
$rs = '';
if (@openssl_private_encrypt($data, $rs, $prikey) === FALSE) {
return NULL;
}
return $rs;
}
示例11: privateEncrypt
public static function privateEncrypt($privateKey, $data)
{
if (!strstr($privateKey, 'BEGIN PRIVATE KEY')) {
$privateKey = self::lengthenPrivateKey($privateKey);
}
$key_resource = openssl_get_privatekey($privateKey);
openssl_private_encrypt($data, $crypttext, $key_resource);
return base64_encode($crypttext);
}
示例12: encrypt1
public function encrypt1($data)
{
if (openssl_private_encrypt($data, $encrypted, $this->privkey)) {
$data = base64_encode($encrypted);
} else {
echo '错误';
}
return $data;
}
示例13: encrypt
/**
* Encrypts the given data.
*
* @param string $rawData The data to encrypt.
* @param int $padding The padding to use for encryption.
* @return string when the given data cannot be encrypted.
*/
public function encrypt(string $rawData, int $padding = OPENSSL_PKCS1_PADDING) : string
{
OpenSSL::resetErrors();
if (openssl_private_encrypt($rawData, $encrypted, $this->resource, $padding) === false) {
// @codeCoverageIgnoreStart
throw new OpenSSLException(OpenSSL::getErrors(), 'Could not encrypt the given data with this private key.');
// @codeCoverageIgnoreEnd
}
return (string) $encrypted;
}
示例14: encrypt
public function encrypt($text)
{
if ($this->key) {
$ret = '';
if (openssl_private_encrypt($text, $ret, $this->key)) {
return base64_encode($ret);
}
}
return null;
}
示例15: encryptByPrivateKey
public static function encryptByPrivateKey($data)
{
$pi_key = openssl_pkey_get_private(file_get_contents(dirname(__DIR__) . '/configure/seller_rsa_private_key.pem'));
//这个函数可用来判断私钥是否是可用的,可用返回资源id Resource id
$encrypted = "";
openssl_private_encrypt($data, $encrypted, $pi_key, OPENSSL_PKCS1_PADDING);
//私钥加密
return base64_encode($encrypted);
//加密后的内容通常含有特殊字符,需要编码转换下,在网络间通过url传输时要注意base64编码是否是url安全的
}