PHP rsa密钥生成 加密解密

 $privkey,
            'pubkey'  => $pubkey
        );
    }
}
 
 
 
 
//举个粒子
$Rsa = new Rsa();
$keys = $Rsa->new_rsa_key(); //生成完key之后应该记录下key值,这里省略
p($keys);
$privkey = $keys['privkey'];
$pubkey  = $keys['pubkey'];
 
//初始化rsaobject
$Rsa->init($privkey, $pubkey,TRUE);
 
//原文
$data = '你妈妈让你回家吃饭了';
 
//私钥加密示例
$encode = $Rsa->priv_encode($data);
p($encode);
$ret = $Rsa->pub_decode($encode);
p($ret);
 
//公钥加密示例
$encode = $Rsa->pub_encode($data);
 
p($encode);
$ret = $Rsa->priv_decode($encode);
p($ret);
 
 
 
function p($str){
    echo '
';
    print_r($str);
    echo '
'; }


你可能感兴趣的:(PHP相关)