PHP AES加密学习笔记
<?php //--------第一种AES-CBC加密方案-------- //仅为理解之用 $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); #128位 = 16字节 iv必须16字节 $key128 = '1234567890123456'; $iv = '1234567890123456'; $cleartext = 'hello'; #待加密的字符串 if (mcrypt_generic_init($cipher, $key128, $iv) != -1) { // PHP pads with NULL bytes if $cleartext is not a multiple of the block size.. //如果$cleartext不是128位也就是16字节的倍数,补充NULL字符满足这个条件,返回的结果的长度一样 $cipherText = mcrypt_generic($cipher,$cleartext ); mcrypt_generic_deinit($cipher); // Display the result in hex. //很明显,结果也是16字节的倍数.1个字节用两位16进制表示,所以下面输出的是32的倍数位16进制的字符串 echo '第一种AES加密方案:<br>'; printf("128-bit encrypted result:\n%s\n\n",bin2hex($cipherText)); echo '<br>';echo '<br>'; } //--------第一种AES加密方案-------- ?>转载来源:http://www.chilkatsoft.com/p/php_aes.asp http://www.cnblogs.com/adylee/archive/2007/09/14/893438.html 转载来源:http://blog.csdn.net/shushengsky/archive/2009/12/13/4961861.aspx
<?php //--------第二种AES-ECB加密方案-------- //加密 echo '第二种AES加密方案:<br>'; $key = '1234567890123456'; $content = 'hello'; $padkey = pad2Length($key,16); $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, ''); $iv_size = mcrypt_enc_get_iv_size($cipher); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); #IV自动生成? echo '自动生成iv的长度:'.strlen($iv).'位:'.bin2hex($iv).'<br>'; if (mcrypt_generic_init($cipher, pad2Length($key,16), $iv) != -1) { // PHP pads with NULL bytes if $content is not a multiple of the block size.. $cipherText = mcrypt_generic($cipher,pad2Length($content,16) ); mcrypt_generic_deinit($cipher); mcrypt_module_close($cipher); // Display the result in hex. printf("128-bit encrypted result:\n%s\n\n",bin2hex($cipherText)); print("<br />"); } //解密 $mw = bin2hex($cipherText); $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, ''); if (mcrypt_generic_init($td, $padkey, $iv) != -1) { $p_t = mdecrypt_generic($td, hexToStr($mw)); mcrypt_generic_deinit($td); mcrypt_module_close($td); $p_t = trimEnd($p_t); echo '解密:'; print($p_t); print("<br />"); print(bin2hex($p_t)); echo '<br><br>'; } //将$text补足$padlen倍数的长度 function pad2Length($text, $padlen){ $len = strlen($text)%$padlen; $res = $text; $span = $padlen-$len; for($i=0; $i<$span; $i++){ $res .= chr($span); } return $res; } //将解密后多余的长度去掉(因为在加密的时候 补充长度满足block_size的长度) function trimEnd($text){ $len = strlen($text); $c = $text[$len-1]; if(ord($c) <$len){ for($i=$len-ord($c); $i<$len; $i++){ if($text[$i] != $c){ return $text; } } return substr($text, 0, $len-ord($c)); } return $text; } //16进制的转为2进制字符串 function hexToStr($hex) { $bin=""; for($i=0; $i<strlen($hex)-1; $i+=2) { $bin.=chr(hexdec($hex[$i].$hex[$i+1])); } return $bin; } //--------第二种AES加密方案--------
<?php //--------第三种AES-ECB加密方案-------- echo '第三种AES加密方案:<br>'; $key = '1234567890123456'; $key = pad2Length($key,16); $iv = 'asdff'; $content = 'hello'; $content = pad2Length($content,16); $AESed = bin2hex( mcrypt_encrypt(MCRYPT_RIJNDAEL_128,$key,$content,MCRYPT_MODE_ECB,$iv) ); #加密 echo "128-bit encrypted result:".$AESed.'<br>'; $jiemi = mcrypt_decrypt(MCRYPT_RIJNDAEL_128,$key,hexToStr($AESed),MCRYPT_MODE_ECB,$iv); #解密 echo '解密:'; echo trimEnd($jiemi); //--------第三种AES加密方案-------- ?> #KEY长度无限制,IV长度必须是block_size的倍数 #如果是MCRYPT_MODE_ECB加密,结果与KEY有关,与IV无关 #如果是MCRYPT_MODE_CBC加密,结果与KEY有关,与IV有关

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

AI Hentai Generator
Générez AI Hentai gratuitement.

Article chaud

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Sujets chauds

Dans ce chapitre, nous comprendrons les variables d'environnement, la configuration générale, la configuration de la base de données et la configuration de la messagerie dans CakePHP.

PHP 8.4 apporte plusieurs nouvelles fonctionnalités, améliorations de sécurité et de performances avec une bonne quantité de dépréciations et de suppressions de fonctionnalités. Ce guide explique comment installer PHP 8.4 ou mettre à niveau vers PHP 8.4 sur Ubuntu, Debian ou leurs dérivés. Bien qu'il soit possible de compiler PHP à partir des sources, son installation à partir d'un référentiel APT comme expliqué ci-dessous est souvent plus rapide et plus sécurisée car ces référentiels fourniront les dernières corrections de bogues et mises à jour de sécurité à l'avenir.

Pour travailler avec la date et l'heure dans cakephp4, nous allons utiliser la classe FrozenTime disponible.

Pour travailler sur le téléchargement de fichiers, nous allons utiliser l'assistant de formulaire. Voici un exemple de téléchargement de fichiers.

Dans ce chapitre, nous allons apprendre les sujets suivants liés au routage ?

CakePHP est un framework open source pour PHP. Il vise à faciliter grandement le développement, le déploiement et la maintenance d'applications. CakePHP est basé sur une architecture de type MVC à la fois puissante et facile à appréhender. Modèles, vues et contrôleurs gu

Visual Studio Code, également connu sous le nom de VS Code, est un éditeur de code source gratuit – ou environnement de développement intégré (IDE) – disponible pour tous les principaux systèmes d'exploitation. Avec une large collection d'extensions pour de nombreux langages de programmation, VS Code peut être c

Le validateur peut être créé en ajoutant les deux lignes suivantes dans le contrôleur.
