好得很程序员自学网
  • 首页
  • 后端语言
    • C#
    • PHP
    • Python
    • java
    • Golang
    • ASP.NET
  • 前端开发
    • Angular
    • react框架
    • LayUi开发
    • javascript
    • HTML与HTML5
    • CSS与CSS3
    • jQuery
    • Bootstrap
    • NodeJS
    • Vue与小程序技术
    • Photoshop
  • 数据库技术
    • MSSQL
    • MYSQL
    • Redis
    • MongoDB
    • Oracle
    • PostgreSQL
    • Sqlite
    • 数据库基础
    • 数据库排错
  • CMS系统
    • HDHCMS
    • WordPress
    • Dedecms
    • PhpCms
    • 帝国CMS
    • ThinkPHP
    • Discuz
    • ZBlog
    • ECSHOP
  • 高手进阶
    • Android技术
    • 正则表达式
    • 数据结构与算法
  • 系统运维
    • Windows
    • apache
    • 服务器排错
    • 网站安全
    • nginx
    • linux系统
    • MacOS
  • 学习教程
    • 前端脚本教程
    • HTML与CSS 教程
    • 脚本语言教程
    • 数据库教程
    • 应用系统教程
  • 新技术
  • 编程导航
    • 区块链
    • IT资讯
    • 设计灵感
    • 建站资源
    • 开发团队
    • 程序社区
    • 图标图库
    • 图形动效
    • IDE环境
    • 在线工具
    • 调试测试
    • Node开发
    • 游戏框架
    • CSS库
    • Jquery插件
    • Js插件
    • Web框架
    • 移动端框架
    • 模块管理
    • 开发社区
    • 在线课堂
    • 框架类库
    • 项目托管
    • 云服务

当前位置:首页>CMS系统>Dedecms
<tfoot draggable='sEl'></tfoot>

phpdec关键字 php use关键字

很多站长朋友们都不太清楚phpdec关键字,今天小编就来给大家整理phpdec关键字,希望对各位有所帮助,具体内容如下:

本文目录一览: 1、 PHP如何格式化金钱数字? 2、 php 怎么生成rsa加密的公钥和私钥 3、 php代码提示:Parse error: syntax error, unexpected T_LOGICAL_XOR, expecting T_STRING 4、 关于php des 加密 密钥长度问题 PHP如何格式化金钱数字?

PHP格式化数字的函数是number_format

关于他的用法如下:

语法: string number_format(float number, int [decimals], string [dec_point], string [thousands_sep]);

返回值: 字符串

函数种类: 数学运算

内容说明

本函数用来将浮点参数 number 格式化。若没加参数 decimals 则返回的字符串只要整数部份,加了此参数才依参数指定的小数点位数返回。参数 dec_point 表示小数点的表示方式方法,默认值是 ".",若需要转换成其它的小数点就可以在这个参数改掉。参数 thousands_sep 为整数部份每三位的分隔符号,默认值是 ","。本函数最特别的地方就是参数数目,最少要有一个,也就是欲格式化的字符串;也可以有二个或者四个参数,但不能用三个参数。治募?注意的是指定小数点的位数之后的数字直接舍弃,没有四舍五入的情形。

使用范例

<?

$short_pi = "3.14159";

$my_pi = number_format($short_pi, 2);

echo $my_pi."\n"; // 3.14

$foo = 850017.9021;

$new_foo = number_format($foo, 3, ".", " ");

echo $new_foo."\n"; // 850 017.902

?>

php 怎么生成rsa加密的公钥和私钥

附上出处链接:

四,用PHP生成密钥

PEAR::Crypt_RSA的Crypt_RSA_KeyPair类可以生成密钥。调用步骤如下:

require_once('Crypt/RSA.php');

$math_obj = Crypt_RSA_MathLoader::loadWrapper();

$key_pair = new Crypt_RSA_KeyPair($key_lenth);

if (!$key_pair->isError()){

$public_key = $key_pair->getPublicKey();

$private_key = $key_pair->getPrivateKey();

$e =$math_obj->hexstr($math_obj->bin2int($public_key->getExponent()));

$d =$math_obj->hexstr($math_obj->bin2int($private_key->getExponent()));

$n =$math_obj->hexstr($math_obj->bin2int($public_key->getModulus()));

}

hexstr()是自己添加的函数,用来把十进制字符串转换为十六进制。对Crypt_RSA_Math_GMP很简单,只需:

function hexstr($num){

return gmp_strval($num,16);

}

对Crypt_RSA_Math_BCMath略麻烦些:

function hexstr($num){

$result = '';

do{

$result = sprintf('%02x',intval(bcmod($num,256))).$result;

$num = bcdiv($num, 256);

}while(bccomp($num, 0));

return ltrim($result,'0');

}

五,用php生成密钥(二)

为了提高加密速度,一般选一个较小的e。比较常用的是3、17、257、65537几个素数。

generate()生成密钥的算法是依次计算p,q,n,e,d。因此做了如下改动,以便可以自己选e值:

原来的:

function Crypt_RSA_KeyPair($key_len, $wrapper_name = 'default', $error_handler = '')

改后增加一个参数e:

function Crypt_RSA_KeyPair($key_len, $e = null, $wrapper_name = 'default', $error_handler = '')

这个函数调用generate()。效应地:

function generate($key_len = null)

也增加一个参数e:

function generate($key_len = null, $e = null)

把CRYPT_RSA-1.0.0的KeyPair.php中属于generate()的245~271行改动顺序,由e确定p和q:

if($e != null$this->_math_obj->cmpAbs($e,2)>0)

$e = $this->_math_obj->nextPrime($this->_math_obj->dec($e));//取个素数

else

{

while(true)

{

$e = $this->_math_obj->getRand($q_len, $this->_random_generator);

if ($this->_math_obj->cmpAbs($e,2)<=0)

continue;

$e = $this->_math_obj->nextPrime($this->_math_obj->dec($e));

break;

}

}

do{

$p = $this->_math_obj->getRand($p_len, $this->_random_generator, true);

$p = $this->_math_obj->nextPrime($p);

do{

do{

$q = $this->_math_obj->getRand($q_len, $this->_random_generator, true);

$tmp_len = $this->_math_obj->bitLen($this->_math_obj->mul($p, $q));

if ($tmp_len < $key_len)

$q_len++;

elseif ($tmp_len > $key_len)

$q_len--;

} while ($tmp_len != $key_len);

$q = $this->_math_obj->nextPrime($q);

$tmp = $this->_math_obj->mul($p, $q);

} while ($this->_math_obj->bitLen($tmp) != $key_len);

// $n - is shared modulus

$n = $this->_math_obj->mul($p, $q);

// generate public ($e) and private ($d) keys

$pq = $this->_math_obj->mul($this->_math_obj->dec($p), $this->_math_obj->dec($q));

if($this->_math_obj->isZero($this->_math_obj->dec($this->_math_obj->gcd($e, $pq))))

break;

}while(true);

(网易的服务真体贴啊,连pre标记里面的东西都给改。还改不好)这样,如果要生成e为3的1024位密钥,可以如下调用:

$key_pair = new Crypt_RSA_KeyPair(1024,3);

六,干什么用

加密比较重要的数据。比如注册时用户输入的密码。

登录时把密码hmac一下就可以防止重放攻击(replay attack)了。对注册不存在这种攻击,但有密码泄露的危险。上传密码hash那点安全性根本不算什么。这个可以用RSA加密解决。

不过,对中间人攻击还是没办法。

另外一个

php代码提示:Parse error: syntax error, unexpected T_LOGICAL_XOR, expecting T_STRING

function XOR($str1,$str2) {

$temp1=Array();

$temp2=Array();

$hex = "";

if (strlen($str1)!= strlen($str2)) {

echo "异或数据长度不等";

}

for ($i = 0; $i < strlen($str1); $i++) {

$temp1[]=substr($str1,$i,1); //将单个字符存到数组当中------------改动

$temp2[]=substr($str2,$i,1); //将单个字符存到数组当中-----------改动

//$temp1[$i];

$hex = $hex+ strToHex($temp1[$i] ^ $temp2[$i]);

}

return strtoupper($hex);

}

看看这样还报错吗

希望对你有用,望采纳

关于php des 加密 密钥长度问题

php5.6的key长度要求是32字节的,你这个明显不满足要求的。

参考以下写法:

<?php

# --- ENCRYPTION ---

# the key should be random binary, use scrypt, bcrypt or PBKDF2 to

# convert a string into a key

# key is specified using hexadecimal

$key = pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3");

# show key size use either 16, 24 or 32 byte keys for AES-128, 192

# and 256 respectively

$key_size = strlen($key);

echo "Key size: " . $key_size . "\n";

$plaintext = "This string was AES-256 / CBC / ZeroBytePadding encrypted.";

# create a random IV to use with CBC encoding

$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);

$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);

# creates a cipher text compatible with AES (Rijndael block size = 128)

# to keep the text confidential

# only suitable for encoded input that never ends with value 00h

# (because of default zero padding)

$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key,

$plaintext, MCRYPT_MODE_CBC, $iv);

# prepend the IV for it to be available for decryption

$ciphertext = $iv . $ciphertext;

# encode the resulting cipher text so it can be represented by a string

$ciphertext_base64 = base64_encode($ciphertext);

echo $ciphertext_base64 . "\n";

# === WARNING ===

# Resulting cipher text has no integrity or authenticity added

# and is not protected against padding oracle attacks.

# --- DECRYPTION ---

$ciphertext_dec = base64_decode($ciphertext_base64);

# retrieves the IV, iv_size should be created using mcrypt_get_iv_size()

$iv_dec = substr($ciphertext_dec, 0, $iv_size);

# retrieves the cipher text (everything except the $iv_size in the front)

$ciphertext_dec = substr($ciphertext_dec, $iv_size);

# may remove 00h valued characters from end of plain text

$plaintext_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key,

$ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec);

echo $plaintext_dec . "\n";

?>

关于phpdec关键字的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。

查看更多关于phpdec关键字 php use关键字的详细内容...

声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did167386
更新时间:2023-03-28   阅读:27次

上一篇: php指定网站目录 php的网页文件根目录是什么

下一篇:php追加文件内容 php添加

相关资讯

最新资料更新

  • 1.DedeCMS图集中缩略图不显示的解决方法
  • 2.DEDECMS后台文章管理中增加批量添加tag标签功能示例
  • 3.详解自己动手添加一个函数实现任意字段调用
  • 4.dedecms的dedesql.class.php on line 489错误的解决方法
  • 5.dedecms 模板调用解析最简代码
  • 6.dedecms编辑修改文章后使发布时间更新为最新时间的解决方法
  • 7.dedecms友情链接标签flink使用说明及实例代码
  • 8.DedeCms后台添加编辑文章空白的解决方法
  • 9.Dedecms网站地图获取文章列表支持标签调用的方法
  • 10.DEDECMS 扩展标签和dede自定义标签实现方法
  • 11.织梦dedecms会员注册邮件验证设置方法
  • 12.详解解决织梦dede:title字数限制的两种方法
  • 13.DedeCms后台登录一片空白的解决方法
  • 14.dedecms网页模板编写介绍
  • 15.织梦DEDECMS网站栏目页获取当前顶级栏目名称的标签
  • 16.DEDE列表调用有缩图显示缩图,无缩图则不显示缩图的方法
  • 17.解决{dede:arclist keyword=动态获取关键词}
  • 18.DedeCms制作谷歌xml格式网站地图的方法
  • 19.DedeCMS编辑器fck更换成eWebEditor编辑器具体步骤
  • 20.dedeCms批量修改文章发布时间的方法

CopyRight:2016-2025好得很程序员自学网 备案ICP:湘ICP备09009000号-16 http://haodehen.cn
本站资讯不构成任何建议,仅限于个人分享,参考须谨慎!
本网站对有关资料所引致的错误、不确或遗漏,概不负任何法律责任。
本网站刊载的所有内容(包括但不仅限文字、图片、LOGO、音频、视频、软件、程序等)版权归原作者所有。任何单位或个人认为本网站中的内容可能涉嫌侵犯其知识产权或存在不实内容时,请及时通知本站,予以删除。

网站内容来源于网络分享,如有侵权发邮箱到:kenbest@126.com,收到邮件我们会即时下线处理。
网站框架支持:HDHCMS   51LA统计 百度统计
Copyright © 2018-2025 「好得很程序员自学网」
[ SiteMap ]