《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加密解密算法相关推荐

  1. java des加密解密_Java实现的DES加密解密工具类实例

    本文实例讲述了Java实现的DES加密解密工具类.分享给大家供大家参考,具体如下: 一个工具类,很常用,不做深入研究了,那来可直接用 DesUtil.java package lsy; import ...

  2. php64解密,PHP 用base64兑现加密解密

    PHP 用base64实现加密解密 php中用base64实现加密解密:    base64_encode() 和 base64_decode() 进行加密和解密. 语法:    string bas ...

  3. 加密解密系列文章之 - ASCII 加密解密(最简单的加密解密) 上

    前言: 首先.在这里声明.本人没学过加密解密专业以及没有对加密解密做过任何的系统学习.文章用来记录我自己学到的加密解密的一些我理解的东西,有错误之处欢迎大家指出.谢谢. 加密解密.在以前我的眼里.是灰 ...

  4. 加密解密系列文章之 - ASCII 加密解密(最简单的加密解密) 下

    继上一篇 加密解密系列文章之 - ASCII 加密解密(最简单的加密解密) 上 的下篇. 我在 上 篇里 已经给大家说了最基本的ASCII 加密 解密的东西.然后再最后 我们说了ASCII加密解密的问 ...

  5. php结合md5的加密解密,php结合md5的加密解密算法实例

    本文实例讲述了php结合md5的加密解密算法.分享给大家供大家参考,具体如下: /* * Created on 2016-9-30 * */ function encrypt($data, $key) ...

  6. 加密解密php,PHP实现的加密解密处理类

    本文实例讲述了PHP实现的加密解密处理类.分享给大家供大家参考,具体如下: /*=========================================================== ...

  7. java 文件 加解密_Java实现文件的加密解密功能示例

    Java实现文件的加密解密功能示例 发布时间:2020-10-05 22:05:15 来源:脚本之家 阅读:86 作者:FC WORLD!!! 本文实例讲述了Java实现文件的加密解密功能分享给大家供 ...

  8. java实现文件加密与解密_Java实现文件的加密解密功能示例

    本文实例讲述了Java实现文件的加密解密功能分享给大家供大家参考,具体如下: package com.copy.encrypt; import java.io.File; import java.io ...

  9. c语言字符串md5加密解密,.net core使用MD5加密解密字符串

    本文实例为大家分享了.net core使用MD5加密解密字符串的具体代码,供大家参考,具体内容如下 /// /// 加密 /// /// 要加密的文本 /// 秘钥 /// public static ...

  10. java对sha1的解密_Java实现文件的加密解密功能示例

    本文实例讲述了java实现文件的加密解密功能分享给大家供大家参考,具体如下: package com.copy.encrypt; import java.io.file; import java.io ...

最新文章

  1. 对于在git上面拉代码报“error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054“解决方法
  2. PAT甲级1084 Broken Keyboard:[C++题解]字符串处理、双指针算法
  3. mysql的driver和url_数据库连接driverClass和jdbcUrl大全
  4. EduCoder Linux 文件/目录管理
  5. Pytorch在colab和kaggle中使用TensorBoard/TensorboardX可视化
  6. rabbitmq direct 多个消费者_rabbitMQ消息队列入门介绍
  7. cad缩放_mac有没有好用的cad看图软件?CAD迷你看图 for Mac4.4.1激活版分享给大家...
  8. 计算机232接口接线图,RS485电缆(电脑和变频器的连线)如何接法!RS232接法知道的2-3 3-2 5-5-工业支持中心-西门子中国...
  9. 目标检测 3—— 人脸检测
  10. 【所见即所得】数据分析最有用的25个 Matplotlib图【附代码】
  11. ARM基础学习-寄存器寻址方式和指令
  12. xpath prase string
  13. 笔记本win10宽带共享wifi热点教程
  14. 数商云采购管理系统支付结算功能详解,实现建筑工程企业采购业务智能化管理
  15. html5动态加载图片和加载视频
  16. Causal Reasoning from Meta-reinforcement Learning(自用笔记)
  17. TEB算法详解 参数详解
  18. Java:extends 和 implements 的区别
  19. c++由动态库dll文件生成lib文件的方法
  20. 软件测试是什么?具体的工作内容是什么?有前途吗?

热门文章

  1. windows系统开机黑屏只有鼠标解决方法
  2. 篮球计分代码java_单片机课程设计(篮球记分器)
  3. 机器学习与时间序列预测
  4. 5G时代,将为无人机通讯传输带来哪些新变化?
  5. ASC认证|水产ASC标签正逐步进入国人视野
  6. 一种不太聪明的电话语音识别方案
  7. 2021-2027全球与中国微型激光投影仪市场现状及未来发展趋势
  8. HP ProBook 4416s XP系统安装办法
  9. 玉米社:外链、反链、内链、友链的区别与联系详解
  10. linux卸载摄像头,如何在 Linux 中禁用内置摄像头