示例#1
0
function main($crypted)
{
    $rsa = new Rsa();
    if ($crypted) {
        $crypted = base64_decode($crypted);
    } else {
        $crypted = $rsa->rsaEncrypt("*****@*****.**");
        echo "encrypt base64:" . base64_encode($crypted) . "\n";
    }
    $decrypted = $rsa->rsaDecrypt($crypted);
    echo "encrypt and decrypt:" . $decrypted . "\n";
}
示例#2
0
 static function selloDigital($cadena, $archivo)
 {
     $key = Rsa::cargarLlavePrivada($archivo);
     $private_key = Rsa::obtenerLlavePrivada($key);
     $sello = Rsa::generarSelloDigital($cadena, $private_key);
     return $sello;
 }
示例#3
0
 /**
  * 生成签名结果
  *
  * @param $para_sort 已排序要签名的数组
  *
  * @return 签名结果字符串
  */
 function buildRequestMysign($para_sort)
 {
     //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
     $prestr = Core::createLinkstring($para_sort);
     $mysign = "";
     switch (strtoupper(trim($this->alipay_config['sign_type']))) {
         case "RSA":
             $mysign = Rsa::rsaSign($prestr, $this->alipay_config['private_key_path']);
             break;
         default:
             $mysign = "";
     }
     return $mysign;
 }
示例#4
0
 /**
  * 显示登录页(默认Action)
  */
 function doDefault()
 {
     $this->debug(session_id());
     $page = $this->app->page();
     $page->params['template'] = $base = dirname(__FILE__) . '/rsademo.tpl';
     $result = null;
     //$_POST['en']是客户端用RSA加密后的字符串
     if ($_POST['en']) {
         $result = Rsa::decrypt($_POST['en']);
         $result = "The plain text is:" . $result;
     }
     list($pwd, $ssid) = explode("\n", $result);
     $this->debug($pwd);
     $this->debug($ssid);
     $page->value("result", $result);
     $page->output();
 }
示例#5
0
function DecryptString($sourceStr)
{
    $key = base64_encode(pack("H*", $sourceStr));
    return Rsa::privDecrypt($key, true);
}
示例#6
0
 public function verify($data)
 {
     return Rsa::rsa_verify($data, $this->public_key, $this->modulus, $this->key_length);
 }
示例#7
0
<?php

/**
 * 支持各个分离系统的会员信息对接
 * @author winsen
 * @date 2014-11-20
 */
include '../library/init.inc.php';
$loader->includeClass('Rsa');
//接收数据统一使用json格式的RSA私钥加密的密文的base64编码字符串
//返回也是相同的格式
$data = isset($_POST['data']) ? $_POST['data'] : '';
$data = str_replace(' ', '+', $data);
$response = array();
$rsa = new Rsa();
if ($data) {
    $data = $rsa->public_key_decrypt($data, 'base64', 'key/outer_public_key.pem');
    if ($data) {
        $data = json_decode($data);
    }
    if ($data->opera == 'get') {
        $code = $data->code;
        //OAuth用于获取accessToken的code
        $publicAccount = $db->escape($data->account);
        //需要对接程序提供公众号信息
        $getInfo = 'select `appID`,`appsecret` from `' . $db_prefix . 'publicAccount` where `account`=\'' . $publicAccount . '\'';
        $info = $db->fetchRow($getInfo);
        $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code';
        $url = sprintf($url, $info['appID'], $info['appsecret'], $code);
        $wechatInfo = get($url);
        $wechatInfo = json_decode($wechatInfo);
示例#8
0
     * 私匙加密
     * @param  [type] $data [description]
     * @return [type]       [description]
     */
    public static function encrypt($data)
    {
        if (openssl_public_encrypt($data, $encrypted, self::getPublicKey())) {
            $data = base64_encode($encrypted);
        } else {
            throw new Exception('Unable to encrypt data. Perhaps it is bigger than the key size?');
        }
        return $data;
    }
}
//JS->PHP传输RSA加密解密测试
$password = $_POST['password'];
echo "Password Source String:<br/>" . $password;
echo "<br/>";
$key = base64_encode(pack("H*", $password));
echo "Password Decrypt String:" . Rsa::privDecrypt($key, true);
echo "<br/>";
$username = $_POST['username'];
echo 'Username Source String:<br/>' . $username . '<br/>';
$key = base64_encode(pack("H*", $username));
echo "Username DecryptString:" . Rsa::privDecrypt($key, true);
//echo '<br>';
//PHP->PHP RSA加密解密测试
//$key = Rsa::encrypt('测试中文rsa加密');
//echo $key;
//echo '<br/>';
//echo Rsa::privDecrypt($key);
示例#9
0
文件: demo.php 项目: huoshi5151/RSA
<?php

/**
 * Rsa 加密 解密 demo
 * @author Wang [BBG]
 */
require_once 'Rsa.php';
try {
    $rsa = new Rsa();
    $str = '宝贝购 BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com BBG baobeigou.com 宝贝购BBG ';
    //私钥加密
    $data = $rsa->privateKeyEncode($str);
    echo $data . '<br><br><br>';
    //公钥解密
    $decode = $rsa->decodePrivateEncode($data);
    echo $decode . '<br><br><br>';
    //公钥加密
    $pdata = $rsa->publicKeyEncode('Hello World !, 世界 你好!');
    echo $pdata . '<br><br><br>';
    //私钥解密
    $pdecode = $rsa->decodePublicEncode($pdata);
    echo $pdecode . '<br><br><br>';
} catch (Exception $exc) {
    echo $exc->getMessage();
}
示例#10
0
 public function testCreateSignerWithAutomaticType()
 {
     $stub = new Rsa();
     $signer = $stub->signer();
     $this->assertInstanceOf(\Lcobucci\JWT\Signer\Rsa\Sha256::class, $signer);
 }
示例#11
0
    $cadena_original .= "|{$cantidad2}|{$unidad2}|{$d2}|" . number_format($precio2, 2, '.', '') . "|" . number_format($monto2, 2, '.', '');
}
if ($d3 != "") {
    $cadena_original .= "|{$cantidad3}|{$unidad3}|{$d3}|" . number_format($precio3, 2, '.', '') . "|" . number_format($monto3, 2, '.', '');
}
if ($d4 != "") {
    $cadena_original .= "|{$cantidad4}|{$unidad4}|{$d4}|" . number_format($precio4, 2, '.', '') . "|" . number_format($monto4, 2, '.', '');
}
if ($d5 != "") {
    $cadena_original .= "|{$cantidad5}|{$unidad5}|{$d5}|" . number_format($precio5, 2, '.', '') . "|" . number_format($monto5, 2, '.', '');
}
//detalle de impuestos
$cadena_original .= "|IVA|" . $_REQUEST['iva'] . "|" . number_format($iva, 2, '.', '') . "|" . number_format($iva, 2, '.', '') . "||";
$cadena_original = str_replace("  ", " ", $cadena_original);
//Digestion SHA1, firmamos con nuestra clave y pasamos a base 64, requiere de openssl instalado
$sello = Rsa::selloDigital($cadena_original, $archivo_key);
$pdf->SetFont('Arial', 'B', 5);
$pdf->Cell(42, 3, "", 0, 0, 'C');
$pdf->MultiCell(0, 3, utf8_decode("Cadena Original"), 0, 'L');
$pdf->SetFont('Arial', '', 4);
$pdf->Cell(42, 3, "", 0, 0, 'C');
$pdf->MultiCell(0, 3, utf8_decode($cadena_original), 0, 'L');
$pdf->Ln(1);
$pdf->SetFont('Arial', 'B', 5);
$pdf->Cell(42, 3, "", 0, 0, 'C');
$pdf->MultiCell(0, 3, utf8_decode("Sello Digital"), 0, 'L');
$pdf->SetFont('Arial', '', 4);
$pdf->Cell(42, 3, "", 0, 0, 'C');
$pdf->MultiCell(0, 3, utf8_decode($sello), 0, 'L');
$pdf->Ln(1);
$pdf->SetFont('Arial', 'B', 5);
示例#12
0
        $this->setupPubKey();
        $crypted = base64_decode($crypted);
        $r = openssl_public_decrypt($crypted, $decrypted, $this->_pubKey);
        if ($r) {
            return $decrypted;
        }
        return null;
    }
    public function __destruct()
    {
        @fclose($this->_privKey);
        @fclose($this->_pubKey);
    }
}
//以下是一个简单的测试demo,如果不需要请删除
$rsa = new Rsa('sslkey');
//sslkey为存放密钥的路径,将已有的密钥文件复制到该路径下,公钥名称为pub.key,私钥名称为priv.key
//$rsa->createKey(); //创建一对密钥,如果密钥对已经存在,不需调用
//私钥加密,公钥解密
echo 'source:我是老鳖<br />';
$pre = $rsa->privEncrypt("我是老鳖");
echo 'private encrypted:<br />' . $pre . '<br />';
$pud = $rsa->pubDecrypt($pre);
echo 'public decrypted:' . $pud . '<br />';
//公钥加密,私钥解密
echo 'source:干IT的<br />';
$pue = $rsa->pubEncrypt('干IT的');
echo 'public encrypt:<br />' . $pue . '<br />';
$prd = $rsa->privDecrypt($pue);
echo 'private decrypt:' . $prd;
$p = "BHh8quzSlewEJQ6ZiYOsBRDxUVcSh+fVboVI0YXK2LJNH9v/PRG4VpbmroiJtn9Gp55kVAVHLBgTCwnrd0N2FJE+0M5+n6TzkOul1tSgzo+WZVJWXOFlw0S3m8LMLP0ZtMrfQxj8JtgNbewoFIQ2M3ReYCpLTQ4D1EwxzwT/b88=";
示例#13
0
     * 私匙加密
     * @param  [type] $data [description]
     * @return [type]       [description]
     */
    public static function encrypt($data)
    {
        if (openssl_public_encrypt($data, $encrypted, self::getPublicKey())) {
            $data = base64_encode($encrypted);
        } else {
            throw new Exception('Unable to encrypt data. Perhaps it is bigger than the key size?');
        }
        return $data;
    }
}
//JS->PHP传输RSA加密解密测试
$password = $_POST['password'];
echo "需要解密字符串(password):<br/>" . $password;
echo "<br/>";
$key = base64_encode(pack("H*", $password));
echo "解密后原密码:" . Rsa::privDecrypt($key, true);
echo "<br/>";
$username = $_POST['username'];
echo '需要解密字符串(username):<br/>' . $username . '<br/>';
$key = base64_encode(pack("H*", $username));
echo "解密后原用户名:" . Rsa::privDecrypt($key, true);
//echo '<br>';
//PHP->PHP RSA加密解密测试
//$key = Rsa::encrypt('测试中文rsa加密');
//echo $key;
//echo '<br/>';
//echo Rsa::privDecrypt($key);
示例#14
0
 /**
  * 获取返回时的签名验证结果
  *
  * @param $para_temp 通知返回来的参数数组
  * @param $sign 返回的签名结果
  *
  * @return 签名验证结果
  */
 function getSignVeryfy($para_temp, $sign)
 {
     //除去待签名参数数组中的空值和签名参数
     $para_filter = Core::paraFilter($para_temp);
     //对待签名参数数组排序
     $para_sort = Core::argSort($para_filter);
     //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
     $prestr = Core::createLinkstring($para_sort);
     $isSgin = false;
     switch (strtoupper(trim($this->alipay_config['sign_type']))) {
         case "RSA":
             $isSgin = Rsa::rsaVerify($prestr, trim($this->alipay_config['ali_public_key_path']), $sign);
             break;
         default:
             $isSgin = false;
     }
     return $isSgin;
 }
示例#15
0
 function sign($message, $private_key, $modulus, $keylength)
 {
     $padded = Rsa::add_PKCS1_padding($message, false, $keylength / 8);
     $number = Rsa::binary_to_number($padded);
     $signed = Rsa::pow_mod($number, $private_key, $modulus);
     $result = Rsa::number_to_binary($signed, $keylength / 8);
     return $result;
 }