导航:首页 > 源码编译 > des加密算法php

des加密算法php

发布时间:2022-03-08 01:23:47

‘壹’ php和js的des加密结果不一样

加密的算法都是一样的,建议网上搜一个js的des加密脚本试下

‘贰’ PHP DES加密

详见这里的回答,http://..com/link?url=-JSxo3JUy_cGCbCDx00HIUkOMnSSlEEID-_ ,应该可以满足你的需求。

‘叁’ 用PHP的方法解DES加密

<?php
$key='LY870513';
$ctext='j45Rrzxm0jD62U1w798yBg==';
$ptext=mcrypt_decrypt(MCRYPT_DES,$key,base64_decode($ctext),MCRYPT_MODE_CBC,"x12x34x56120x90xabxcdxef");
//echoiconv('UTF-8','GBK',$ptext);//GBK环境使用,UTF8环境多余不用
echo$ptext;//UTF8环境用
20219241337

由于不清楚原代码的块链接模式,暂时用的CBC,对于短数据可解出。

‘肆’ 关于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*', "");

# 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";
?>

‘伍’ php的des加密用js解密解除乱码,发现2个加密出的东西不一样

JS加密和PHP加密是不同的,虽然都是md5加密,所以你不能直接判断js加密和PHP加密是否相等,毕竟是两种语言,要么都用js的加密,要么都是PHP的

‘陆’ Java用Des方式加密之后,PHP怎么解密

DES是一种标准的数据加密算法,关于这个算法的详细介绍可以参考wiki和网络:
php中有一个扩展可以支持DES的加密算法,是:extension=php_mcrypt.dll
在配置文件中将这个扩展打开还不能够在windows环境下使用
需要将PHP文件夹下的 libmcrypt.dll 拷贝到系统的 system32 目录下,这是通过phpinfo可以查看到mcrypt表示这个模块可以正常试用了。
下面是PHP中使用DES加密解密的一个例子:
//$input - stuff to decrypt
//$key - the secret key to use
function do_mencrypt($input, $key)
{
$input = str_replace(""n", "", $input);
$input = str_replace(""t", "", $input);
$input = str_replace(""r", "", $input);
$key = substr(md5($key), 0, 24);
$td = mcrypt_mole_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$encrypted_data = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_mole_close($td);
return trim(chop(base64_encode($encrypted_data)));
}
//$input - stuff to decrypt
//$key - the secret key to use
function do_mdecrypt($input, $key)
{
$input = str_replace(""n", "", $input);
$input = str_replace(""t", "", $input);
$input = str_replace(""r", "", $input);
$input = trim(chop(base64_decode($input)));
$td = mcrypt_mole_open('tripledes', '', 'ecb', '');
$key = substr(md5($key), 0, 24);
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$decrypted_data = mdecrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_mole_close($td);
return trim(chop($decrypted_data));
}

‘柒’ PHP DES加密函数

两个函数如下:
加密函数:encrypt
function encrypt($encrypt,$key="") {
$iv = mcrypt_create_iv ( mcrypt_get_iv_size ( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ), MCRYPT_RAND );
$passcrypt = mcrypt_encrypt ( MCRYPT_RIJNDAEL_256, $key, $encrypt, MCRYPT_MODE_ECB, $iv );
$encode = base64_encode ( $passcrypt );
return $encode;
}

解密函数:decrypt
function decrypt($decrypt,$key="") {
$decoded = base64_decode ( $decrypt );
$iv = mcrypt_create_iv ( mcrypt_get_iv_size ( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ), MCRYPT_RAND );
$decrypted = mcrypt_decrypt ( MCRYPT_RIJNDAEL_256, $key, $decoded, MCRYPT_MODE_ECB, $iv );
return $decrypted;
}

‘捌’ php怎样用des加密算法给接口加密

所谓的接口加密 是对接口调用的参数加密, php des加密算法 网上有很多. 如:
http://www.cnblogs.com/cocowool/archive/2009/01/07/1371309.html

如果还嫌不安全,那就制定一个token生成规则,按某些服务器端和客户端都拥有的共同属性生成一个随机串,客户端生成这个串,服务器收到请求也校验这个串。.

再或者是用https方式传输

阅读全文

与des加密算法php相关的资料

热点内容
美国疾控发防疫命令 浏览:139
用固定循环编程可以 浏览:879
硅胶压缩比测试 浏览:800
vc命令行编译c 浏览:674
php用户登录界面 浏览:82
安卓车载导航如何卸载自带软件 浏览:714
阶乘的编程c 浏览:415
java视频教程达内 浏览:825
单片机应该怎么学 浏览:420
空气压缩机品牌名称 浏览:346
word文档部分内容加密 浏览:62
压解压软件 浏览:935
java设置excel格式 浏览:957
单片机锁存器地址怎么看 浏览:576
手机硬件编程 浏览:835
如何去除你看文件夹时间 浏览:442
两个加数的和的编程 浏览:796
51单片机lcd显示 浏览:585
hacmp命令 浏览:621
安卓游戏机都有什么 浏览:75