Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1291 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  [Résolu] php sodium chiffrement

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Résolu] php sodium chiffrement

n°2396707
mozaia
Posté le 28-09-2021 à 11:27:57  profilanswer
 

Bonjour,
 
je suis à la fin d'un cours sur la cryptographie - Sécurisez vos données avec la cryptographie, aussi j'essaie de mettre tout cela en pratique…
 
Il s'agit du hachage des mots de passe à l'aide php et sodium.
 
Ce que j'ai fait:

Code :
  1. sudo apt-get install php


Ce qui n'est pas passé:

Code :
  1. thierry@thierry-VirtualBox:~/Dokumente/php$ sudo pecl install -f libsodium
  2. [sudo] Mot de passe de thierry :
  3. sudo: pecl : commande introuvable


De plus j'ai décommenté extension=sodium:

Code :
  1. thierry@thierry-VirtualBox:~/Dokumente/php$ cat /etc/php/7.4/cli/php.ini | grep sodium
  2. extension=sodium


Ensuite j'ai copié le code proposé dans le cours ici ,et j'ai essayé de le lancer:

Code :
  1. thierry@thierry-VirtualBox:~/Dokumente/php$ sudo php -f /home/thierry/Dokumente/php/prog1.php
  2. PHP Warning:  PHP Startup: Unable to load dynamic library 'sodium' (tried: /usr/lib/php/20190902/sodium (/usr/lib/php/20190902/sodium: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/sodium.so (/usr/lib/php/20190902/sodium.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
  3. 55eed5b8a36a8e39c77a6b80bc6515582dd7e01a94f7f83b42242614ad7e5d55
  4. e55cad32fe8af7734495934dd141e1ad5c7d79545f4c22d6b46e79
  5. Hello World
  6. thierry@thierry-VirtualBox:~/Dokumente/php$ php -f /home/thierry/Dokumente/php/prog1.php
  7. PHP Warning:  PHP Startup: Unable to load dynamic library 'sodium' (tried: /usr/lib/php/20190902/sodium (/usr/lib/php/20190902/sodium: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/sodium.so (/usr/lib/php/20190902/sodium.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
  8. d73335f7b9c0c62ad62039a4f8957410f77d971b845635d8d81b88050554ac0f
  9. becbf38c259633d9cfc6b49495122eee916786a91497709bd06b8c
  10. Hello World


 
Je ne connais pas bien php, mais je ne suis pas une quiche. Sans en avoir jamais fait j'arrive à peu près à lire le petit programme.
echo (comme en bash…)
.    (pour appliquer echo deux fois de suite)
PHP_EOL (end of line…)
D'où les trois lignes qui s'affichent en dessous, ok.
 
Apparemment la librairie sodium ne se charge pas dynamiquement, c'est grave ?
 
J'aimerais bien réaliser ces TP et que ça se passe bien.  
Merci pour votre aide.  :)


Message édité par mozaia le 28-09-2021 à 13:26:14

---------------
Dimensions Moebius Sésamath
mood
Publicité
Posté le 28-09-2021 à 11:27:57  profilanswer
 

n°2396709
xtieu
Posté le 28-09-2021 à 11:32:57  profilanswer
 

Hello,
 
La commande pecl ne semble pas dispo sur ta machine,
 
fais un  
 

Code :
  1. sudo apt install php-pear


 
 avant de lancer l'install de la lib


---------------
There's more to life than the boy in that mirror.
n°2396710
mozaia
Posté le 28-09-2021 à 11:43:19  profilanswer
 

exacte, php-pear n'était pas installé, c'est maintenant installé.
 
voilà le résultat:

Code :
  1. thierry@thierry-VirtualBox:~$ sudo pecl install -f libsodium
  2. PHP Warning:  PHP Startup: Unable to load dynamic library 'sodium' (tried: /usr/lib/php/20190902/sodium (/usr/lib/php/20190902/sodium: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/sodium.so (/usr/lib/php/20190902/sodium.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
  3. Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187
  4. PHP Notice:  Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187
  5. Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187
  6. PHP Notice:  Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187
  7. Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187
  8. PHP Notice:  Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187
  9. Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187
  10. PHP Notice:  Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187
  11. WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
  12. downloading libsodium-2.0.23.tgz ...
  13. Starting to download libsodium-2.0.23.tgz (28,505 bytes)
  14. .........done: 28,505 bytes
  15. 4 source files, building
  16. running: phpize
  17. sh: 1: phpize: not found
  18. ERROR: `phpize' failed


 
PS: je suis sur Ubuntu 20.04 en VM.


Message édité par mozaia le 28-09-2021 à 11:45:52

---------------
Dimensions Moebius Sésamath
n°2396712
mechkurt
Posté le 28-09-2021 à 11:50:19  profilanswer
 

Code :
  1. sudo apt-get install -y libsodium-dev


---------------
D3
n°2396714
mozaia
Posté le 28-09-2021 à 11:56:35  profilanswer
 

Code :
  1. thierry@thierry-VirtualBox:~$ sudo apt install -y libsodium-dev
  2. Lecture des listes de paquets... Fait
  3. Construction de l'arbre des dépendances     
  4. Lecture des informations d'état... Fait
  5. Les paquets suivants ont été installés automatiquement et ne sont plus nécessaires :
  6.   linux-headers-5.11.0-27-generic linux-hwe-5.11-headers-5.11.0-27 linux-image-5.11.0-27-generic linux-modules-5.11.0-27-generic linux-modules-extra-5.11.0-27-generic
  7. Veuillez utiliser « sudo apt autoremove » pour les supprimer.
  8. Les NOUVEAUX paquets suivants seront installés :
  9.   libsodium-dev
  10. 0 mis à jour, 1 nouvellement installés, 0 à enlever et 0 non mis à jour.
  11. Il est nécessaire de prendre 169 ko dans les archives.
  12. Après cette opération, 826 ko d'espace disque supplémentaires seront utilisés.
  13. Réception de :1 http://de.archive.ubuntu.com/ubuntu focal/main amd64 libsodium-dev amd64 1.0.18-1 [169 kB]
  14. 169 ko réceptionnés en 0s (732 ko/s)
  15. Sélection du paquet libsodium-dev:amd64 précédemment désélectionné.
  16. (Lecture de la base de données... 261629 fichiers et répertoires déjà installés.)
  17. Préparation du dépaquetage de .../libsodium-dev_1.0.18-1_amd64.deb ...
  18. Dépaquetage de libsodium-dev:amd64 (1.0.18-1) ...
  19. Paramétrage de libsodium-dev:amd64 (1.0.18-1) ...
  20. thierry@thierry-VirtualBox:~$ sudo pecl install -f libsodium
  21. PHP Warning:  PHP Startup: Unable to load dynamic library 'sodium' (tried: /usr/lib/php/20190902/sodium (/usr/lib/php/20190902/sodium: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/sodium.so (/usr/lib/php/20190902/sodium.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
  22. WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
  23. downloading libsodium-2.0.23.tgz ...
  24. Starting to download libsodium-2.0.23.tgz (28,505 bytes)
  25. .........done: 28,505 bytes
  26. 4 source files, building
  27. running: phpize
  28. sh: 1: phpize: not found
  29. ERROR: `phpize' failed


Message édité par mozaia le 28-09-2021 à 11:57:17

---------------
Dimensions Moebius Sésamath
n°2396725
mozaia
Posté le 28-09-2021 à 12:57:49  profilanswer
 

J'ai du nouveau, il faut installer php-dev pour avoir phpize:

Code :
  1. sudo apt install php-dev


 
Et maintenant (voir lignes 140, 141):

Code :
  1. thierry@thierry-VirtualBox:~$ sudo pecl install -f libsodium
  2. WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
  3. downloading libsodium-2.0.23.tgz ...
  4. Starting to download libsodium-2.0.23.tgz (28,505 bytes)
  5. .........done: 28,505 bytes
  6. 4 source files, building
  7. running: phpize
  8. Configuring for:
  9. PHP Api Version:         20190902
  10. Zend Module Api No:      20190902
  11. Zend Extension Api No:   320190902
  12. building in /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23
  13. running: /tmp/pear/temp/libsodium/configure --with-php-config=/usr/bin/php-config
  14. checking for grep that handles long lines and -e... /usr/bin/grep
  15. checking for egrep... /usr/bin/grep -E
  16. checking for a sed that does not truncate output... /usr/bin/sed
  17. checking for pkg-config... /usr/bin/pkg-config
  18. checking pkg-config is at least version 0.9.0... yes
  19. checking for cc... cc
  20. checking whether the C compiler works... yes
  21. checking for C compiler default output file name... a.out
  22. checking for suffix of executables...
  23. checking whether we are cross compiling... no
  24. checking for suffix of object files... o
  25. checking whether we are using the GNU C compiler... yes
  26. checking whether cc accepts -g... yes
  27. checking for cc option to accept ISO C89... none needed
  28. checking how to run the C preprocessor... cc -E
  29. checking for icc... no
  30. checking for suncc... no
  31. checking for system library directory... lib
  32. checking if compiler supports -R... no
  33. checking if compiler supports -Wl,-rpath,... yes
  34. checking build system type... x86_64-pc-linux-gnu
  35. checking host system type... x86_64-pc-linux-gnu
  36. checking target system type... x86_64-pc-linux-gnu
  37. checking for PHP prefix... /usr
  38. checking for PHP includes... -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib
  39. checking for PHP extension directory... /usr/lib/php/20190902
  40. checking for PHP installed headers prefix... /usr/include/php/20190902
  41. checking if debug is enabled... no
  42. checking if zts is enabled... no
  43. checking for gawk... no
  44. checking for nawk... nawk
  45. checking if nawk is broken... no
  46. checking for sodium support... yes, shared
  47. checking for pkg-config... /usr/bin/pkg-config
  48. checking for libsodium... version 1.0.18 found using pkg-config
  49. checking for sodium_add in -lsodium... yes
  50. checking for a sed that does not truncate output... /usr/bin/sed
  51. checking for ld used by cc... /usr/bin/ld
  52. checking if the linker (/usr/bin/ld) is GNU ld... yes
  53. checking for /usr/bin/ld option to reload object files... -r
  54. checking for BSD-compatible nm... /usr/bin/nm -B
  55. checking whether ln -s works... yes
  56. checking how to recognize dependent libraries... pass_all
  57. checking for ANSI C header files... yes
  58. checking for sys/types.h... yes
  59. checking for sys/stat.h... yes
  60. checking for stdlib.h... yes
  61. checking for string.h... yes
  62. checking for memory.h... yes
  63. checking for strings.h... yes
  64. checking for inttypes.h... yes
  65. checking for stdint.h... yes
  66. checking for unistd.h... yes
  67. checking dlfcn.h usability... yes
  68. checking dlfcn.h presence... yes
  69. checking for dlfcn.h... yes
  70. checking the maximum length of command line arguments... 1572864
  71. checking command to parse /usr/bin/nm -B output from cc object... ok
  72. checking for objdir... .libs
  73. checking for ar... ar
  74. checking for ranlib... ranlib
  75. checking for strip... strip
  76. checking if cc supports -fno-rtti -fno-exceptions... no
  77. checking for cc option to produce PIC... -fPIC
  78. checking if cc PIC flag -fPIC works... yes
  79. checking if cc static flag -static works... yes
  80. checking if cc supports -c -o file.o... yes
  81. checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
  82. checking whether -lc should be explicitly linked in... no
  83. checking dynamic linker characteristics... GNU/Linux ld.so
  84. checking how to hardcode library paths into programs... immediate
  85. checking whether stripping libraries is possible... yes
  86. checking if libtool supports shared libraries... yes
  87. checking whether to build shared libraries... yes
  88. checking whether to build static libraries... no
  89. creating libtool
  90. appending configuration tag "CXX" to libtool
  91. configure: patching config.h.in
  92. configure: creating ./config.status
  93. config.status: creating config.h
  94. running: make
  95. /bin/bash /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/libtool --mode=compile cc  -I. -I/tmp/pear/temp/libsodium -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/include -I/tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/main -I/tmp/pear/temp/libsodium -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/libsodium/libsodium.c -o libsodium.lo
  96. mkdir .libs
  97. cc -I. -I/tmp/pear/temp/libsodium -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/include -I/tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/main -I/tmp/pear/temp/libsodium -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/libsodium/libsodium.c  -fPIC -DPIC -o .libs/libsodium.o
  98. /bin/bash /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/libtool --mode=link cc -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/include -I/tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/main -I/tmp/pear/temp/libsodium -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -o sodium.la -export-dynamic -avoid-version -prefer-pic -module -rpath /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/modules  libsodium.lo -lsodium
  99. cc -shared  .libs/libsodium.o  -lsodium  -Wl,-soname -Wl,sodium.so -o .libs/sodium.so
  100. creating sodium.la
  101. (cd .libs && rm -f sodium.la && ln -s ../sodium.la sodium.la)
  102. /bin/bash /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/libtool --mode=install cp ./sodium.la /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/modules
  103. cp ./.libs/sodium.so /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/modules/sodium.so
  104. cp ./.libs/sodium.lai /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/modules/sodium.la
  105. PATH="$PATH:/sbin" ldconfig -n /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/modules
  106. ----------------------------------------------------------------------
  107. Libraries have been installed in:
  108.    /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/modules
  109. If you ever happen to want to link against installed libraries
  110. in a given directory, LIBDIR, you must either use libtool, and
  111. specify the full pathname of the library, or use the `-LLIBDIR'
  112. flag during linking and do at least one of the following:
  113.    - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
  114.      during execution
  115.    - add LIBDIR to the `LD_RUN_PATH' environment variable
  116.      during linking
  117.    - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
  118.    - have your system administrator add LIBDIR to `/etc/ld.so.conf'
  119. See any operating system documentation about shared libraries for
  120. more information, such as the ld(1) and ld.so(8) manual pages.
  121. ----------------------------------------------------------------------
  122. Build complete.
  123. Don't forget to run 'make test'.
  124. running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23" install
  125. Installing shared extensions:     /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23/usr/lib/php/20190902/
  126. running: find "/tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23" | xargs ls -dils
  127. 672022   4 drwxr-xr-x 3 root root   4096 Sep 28 12:52 /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23
  128. 672043   4 drwxr-xr-x 3 root root   4096 Sep 28 12:52 /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23/usr
  129. 672044   4 drwxr-xr-x 3 root root   4096 Sep 28 12:52 /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23/usr/lib
  130. 672045   4 drwxr-xr-x 3 root root   4096 Sep 28 12:52 /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23/usr/lib/php
  131. 672046   4 drwxr-xr-x 2 root root   4096 Sep 28 12:52 /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23/usr/lib/php/20190902
  132. 672041 368 -rwxr-xr-x 1 root root 375152 Sep 28 12:52 /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23/usr/lib/php/20190902/sodium.so
  133. Build process completed successfully
  134. Installing '/usr/lib/php/20190902/sodium.so'
  135. install ok: channel://pecl.php.net/libsodium-2.0.23
  136. configuration option "php_ini" is not set to php.ini location
  137. You should add "extension=sodium.so" to php.ini


Message édité par mozaia le 28-09-2021 à 12:59:39

---------------
Dimensions Moebius Sésamath
n°2396729
mozaia
Posté le 28-09-2021 à 13:25:15  profilanswer
 

Ça fonctionne  :)  
 
En fait il n'est pas nécessaire (voir déconseillé) de décommenter extension=sodium dans /etc/php/7.4/cli/php.ini, sinon on obtient un Warning comme quoi le module est déjà chargé:

Code :
  1. thierry@thierry-VirtualBox:~$ php -f /home/thierry/Dokumente/php/prog1.php
  2. PHP Warning:  Module 'sodium' already loaded in Unknown on line 0
  3. d86995fa1dc563b614a6e7a8819b2efe2b40d5c404203134571c8c4c15571347
  4. dafc451567858b9c2db0fbc92f3501ea630ef36cbaba00b45f3f8c
  5. Hello World


 
En commentant extension=sodium, impeccable !

Code :
  1. thierry@thierry-VirtualBox:~$ php -f /home/thierry/Dokumente/php/prog1.php
  2. 235bb30ce23d123231c2753667bb953d9cb5ef76f90519b6d71f58f2752ed3e7
  3. 3c63694ecc0b57afa7a148f6c84b609eccdd4831d7946acd1fcf52
  4. Hello World



---------------
Dimensions Moebius Sésamath
n°2396742
Hermes le ​Messager
Breton Quiétiste
Posté le 28-09-2021 à 14:22:59  profilanswer
 

Oui donc en fait, ta question n'avait rien à voir avec sodium, mais comment installer et compiler une extension PHP. :D


---------------
Expert en expertises

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  [Résolu] php sodium chiffrement

 

Sujets relatifs
Chiffrement. Quel bibliothèque (pour C#) ou comment utiliser gpg?[Aide] Le chiffrement sur 128 bits ?
[chiffrement] 128 bits? 
Plus de sujets relatifs à : [Résolu] php sodium chiffrement


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR