首页 / PHP / php加密算法blowfish
php加密算法blowfish
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php加密算法blowfish,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2584字,纯文字阅读大概需要4分钟。
内容图文
php加密算法blowfish
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2016-02-14 * Time: 20:03 */function newline() { printf("<br>"); } $cipher = mcrypt_module_open(MCRYPT_BLOWFISH, ‘‘, MCRYPT_MODE_ECB, ‘‘); // The block-size of the Blowfish algorithm is 64-bits, therefore our IV // is always 8 bytes:$iv = ‘12345678‘; $key256 = ‘1234567890123456ABCDEFGHIJKLMNOP‘; $key256 = ‘closewbq‘; $key128 = ‘closewbq‘; printf("iv: %s\n", bin2hex($iv)); newline(); printf("key256: %s\n", bin2hex($key256)); newline(); printf("key128: %s\n", bin2hex($key128)); newline(); $cleartext = ‘The quick brown fox jumped over the lazy dog‘; $cleartext=‘blowfish‘; printf("clearText: %s", $cleartext); newline(); // Do 256-bit blowfish encryption: // The strengh of the encryption is determined by the length of the key // passed to mcrypt_generic_initif (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)); newline(); } // 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)); } mcrypt_module_close($cipher) // ------- // 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 ?>
iv: 3132333435363738
key256: 636c6f7365776271
key128: 636c6f7365776271
clearText: blowfish
256-bit blowfish encrypted:
6a3cbb16daef0ae0
128-bit blowfish encrypted:
6a3cbb16daef0ae0
这是以16进制输出的字符,不是base64输出的结果。
base64结果:NmEzY2JiMTZkYWVmMGFlMA==
https://www.tools4noobs.com/online_tools/decrypt/
iv是忽略不用的。
https://webnet77.net/cgi-bin/helpers/blowfish.pl
算法:blowfish-compat
原文:http://www.cnblogs.com/cb168/p/5189549.html
内容总结
以上是互联网集市为您收集整理的php加密算法blowfish全部内容,希望文章能够帮你解决php加密算法blowfish所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。