php blowfish 解密,PHP实例:php blowfish加密解密算法
《PHP实例:php blowfish加密解密算法》要点:
本文介绍了PHP实例:php blowfish加密解密算法,希望对您有用。如果有疑问,可以联系我们。
PHP教程
/**
* php blowfish 算法
* Class blowfish
*/
class blowfish{
/**
* blowfish + cbc模式 + pkcs5补码 加密
* @param string $str 需要加密的数据
* @return string 加密后base64加密的数据
*/
public function blowfish_cbc_pkcs5_encrypt($str)
{
$cipher = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
//pkcs5补码
$size = mcrypt_get_block_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC);
$str = $this->pkcs5_pad($str, $size);
if (mcrypt_generic_init($cipher, $this->key, $this->iv) != -1)
{
$cipherText = mcrypt_generic($cipher, $str);
mcrypt_generic_deinit($cipher);
return base64_encode($cipherText);
}
mcrypt_module_close($cipher);
}
/**
* blowfish + cbc模式 + pkcs5 解密 去补码
* @param string $str 加密的数据
* @return string 解密的数据
*/
public function blowfish_cbc_pkcs5_decrypt($str)
{
$cipher = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
if (mcrypt_generic_init($cipher, $this->key, $this->iv) != -1)
{
$cipherText = mdecrypt_generic($cipher, base64_decode($str));
mcrypt_generic_deinit($cipher);
return $this->pkcs5_unpad($cipherText);
}
mcrypt_module_close($cipher);
}
private function pkcs5_pad($text, $blocksize){
$pad = $blocksize - (strlen ( $text ) % $blocksize);
return $text . str_repeat ( chr ( $pad ), $pad );
}
private function pkcs5_unpad($str){
$pad = ord($str[($len = strlen($str)) - 1]);
return substr($str, 0, strlen($str) - $pad);
}
}
PHP教程BlowFish加密算法在php的使用第二例
PHP教程
$cipher = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
// The block-size of the Blowfish algorithm is 64-bits, therefore our IV
// is always 8 bytes:
$iv = '12345678';
$key256 = '1234567890123456ABCDEFGHIJKLMNOP';
$key128 = '1234567890123456';
printf("iv: %s\n",bin2hex($iv));
printf("key256: %s\n",bin2hex($key256));
printf("key128: %s\n",bin2hex($key128));
$cleartext = 'The quick brown fox jumped over the lazy dog';
printf("clearText: %s\n\n",$cleartext);
// Do 256-bit blowfish encryption:
// The strengh of the encryption is determined by the length of the key
// passed to mcrypt_generic_init
if (mcrypt_generic_init($cipher, $key256, $iv) != -1)
{
// PHP pads with NULL bytes if $cleartext is not a multiple of the block size..
$cipherText = mcrypt_generic($cipher,$cleartext );
mcrypt_generic_deinit($cipher);
// Display the result in hex.
printf("256-bit blowfish encrypted:\n%s\n\n",bin2hex($cipherText));
}
// 128-bit blowfish encryption:
if (mcrypt_generic_init($cipher, $key128, $iv) != -1)
{
// PHP pads with NULL bytes if $cleartext is not a multiple of the block size..
$cipherText = mcrypt_generic($cipher,$cleartext );
mcrypt_generic_deinit($cipher);
// Display the result in hex.
printf("128-bit blowfish encrypted:\n%s\n\n",bin2hex($cipherText));
}
// -------
// Results
// -------
// You may use these as test vectors for testing your Blowfish implementations...
//
// iv: 3132333435363738
// key256: 313233343536373839303132333435364142434445464748494a4b4c4d4e4f50
// key128: 31323334353637383930313233343536
// clearText: The quick brown fox jumped over the lazy dog
//
// 256-bit blowfish encrypted:
// 276855ca6c0d60f7d9708210440c1072e05d078e733b34b4198d609dc2fcc2f0c30926cdef3b6d52baf6e345aa03f83e
//
// 128-bit blowfish encrypted:
// d2b5abb73208aea3790621d028afcc74d8dd65fb9ea8e666444a72523f5ecca60df79a424e2c714fa6efbafcc40bdca0
?>
PHP教程以上就是本文的全部内容,希望对大家学习php程序设计有所帮助.
php blowfish 解密,PHP实例:php blowfish加密解密算法相关推荐
- java des加密解密_Java实现的DES加密解密工具类实例
本文实例讲述了Java实现的DES加密解密工具类.分享给大家供大家参考,具体如下: 一个工具类,很常用,不做深入研究了,那来可直接用 DesUtil.java package lsy; import ...
- php64解密,PHP 用base64兑现加密解密
PHP 用base64实现加密解密 php中用base64实现加密解密: base64_encode() 和 base64_decode() 进行加密和解密. 语法: string bas ...
- 加密解密系列文章之 - ASCII 加密解密(最简单的加密解密) 上
前言: 首先.在这里声明.本人没学过加密解密专业以及没有对加密解密做过任何的系统学习.文章用来记录我自己学到的加密解密的一些我理解的东西,有错误之处欢迎大家指出.谢谢. 加密解密.在以前我的眼里.是灰 ...
- 加密解密系列文章之 - ASCII 加密解密(最简单的加密解密) 下
继上一篇 加密解密系列文章之 - ASCII 加密解密(最简单的加密解密) 上 的下篇. 我在 上 篇里 已经给大家说了最基本的ASCII 加密 解密的东西.然后再最后 我们说了ASCII加密解密的问 ...
- php结合md5的加密解密,php结合md5的加密解密算法实例
本文实例讲述了php结合md5的加密解密算法.分享给大家供大家参考,具体如下: /* * Created on 2016-9-30 * */ function encrypt($data, $key) ...
- 加密解密php,PHP实现的加密解密处理类
本文实例讲述了PHP实现的加密解密处理类.分享给大家供大家参考,具体如下: /*=========================================================== ...
- java 文件 加解密_Java实现文件的加密解密功能示例
Java实现文件的加密解密功能示例 发布时间:2020-10-05 22:05:15 来源:脚本之家 阅读:86 作者:FC WORLD!!! 本文实例讲述了Java实现文件的加密解密功能分享给大家供 ...
- java实现文件加密与解密_Java实现文件的加密解密功能示例
本文实例讲述了Java实现文件的加密解密功能分享给大家供大家参考,具体如下: package com.copy.encrypt; import java.io.File; import java.io ...
- c语言字符串md5加密解密,.net core使用MD5加密解密字符串
本文实例为大家分享了.net core使用MD5加密解密字符串的具体代码,供大家参考,具体内容如下 /// /// 加密 /// /// 要加密的文本 /// 秘钥 /// public static ...
- java对sha1的解密_Java实现文件的加密解密功能示例
本文实例讲述了java实现文件的加密解密功能分享给大家供大家参考,具体如下: package com.copy.encrypt; import java.io.file; import java.io ...
最新文章
- 对于在git上面拉代码报“error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054“解决方法
- PAT甲级1084 Broken Keyboard:[C++题解]字符串处理、双指针算法
- mysql的driver和url_数据库连接driverClass和jdbcUrl大全
- EduCoder Linux 文件/目录管理
- Pytorch在colab和kaggle中使用TensorBoard/TensorboardX可视化
- rabbitmq direct 多个消费者_rabbitMQ消息队列入门介绍
- cad缩放_mac有没有好用的cad看图软件?CAD迷你看图 for Mac4.4.1激活版分享给大家...
- 计算机232接口接线图,RS485电缆(电脑和变频器的连线)如何接法!RS232接法知道的2-3 3-2 5-5-工业支持中心-西门子中国...
- 目标检测 3—— 人脸检测
- 【所见即所得】数据分析最有用的25个 Matplotlib图【附代码】
- ARM基础学习-寄存器寻址方式和指令
- xpath prase string
- 笔记本win10宽带共享wifi热点教程
- 数商云采购管理系统支付结算功能详解,实现建筑工程企业采购业务智能化管理
- html5动态加载图片和加载视频
- Causal Reasoning from Meta-reinforcement Learning(自用笔记)
- TEB算法详解 参数详解
- Java:extends 和 implements 的区别
- c++由动态库dll文件生成lib文件的方法
- 软件测试是什么?具体的工作内容是什么?有前途吗?