Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: bastbeat en 10 Noviembre 2011, 20:38 pm



Título: Poner contraseña a documento en script
Publicado por: bastbeat en 10 Noviembre 2011, 20:38 pm
Buenas, estoy empezando en esto, y estso dearrollando un script basico...
necesito que me digais como pongo contraseña a un documento, ya lo e intentado con "gpg", pero no me ha ido. Aqui os lo dejo

Código
  1. #!/bin/bash
  2. read -p "Ingresa opcion a: " opcion
  3. read -p "Ingresa opcion b: " opcionb
  4. if [ "$opcion" = "$opcionb" ]; then
  5. if [ ! -d /root/Escritorio/Resultados ]; then
  6. mkdir /root/Escritorio/Resultados
  7. touch /root/Escritorio/Resultados/resultado
  8. echo las variables son iguales >> /root/Escritorio/Resultados/resultado
  9. else
  10. touch /root/Escritorio/Resultados/resultado
  11. echo las variables son iguales >> /root/Escritorio/Resultados/resultado
  12. fi
  13. elif [ ! "$opcion" = "$opcionb" ];then
  14. if [ ! -d /root/Escritorio/Resultados ]; then
  15. mkdir /root/Escritorio/Resultados
  16. touch /root/Escritorio/Resultados/resultado
  17. echo las variables no son iguales >> /root/Escritorio/Resultados/resultado
  18. else
  19. touch /root/Escritorio/Resultados/resultado
  20. echo las variables no son iguales >> /root/Escritorio/Resultados/resultado
  21. fi
  22. fi
  23. read -p "Desea poner contraseña al archivo resultado?: " respuesta
  24. if [ "$respuesta" = si ]; then
  25. gpg -c /root/Escritorio/Resultados/resultados.txt
  26. if [ "$respuesta" = no ]; then
  27. fi
  28. fi
  29. exit 0


Título: Re: Poner contraseña a documento en script
Publicado por: leogtz en 11 Noviembre 2011, 03:08 am
La manera de usar gpg es:

gpg -c archivo

Ejemplo:

Código:
[0 [19:04][leo@archero Desktop]$ cat file.txt 
url1
url2
url3
url4

[0 [19:04][leo@archero Desktop]$ gpg -c file.txt
gpg: directory `/home/leo/.gnupg' created
gpg: new configuration file `/home/leo/.gnupg/gpg.conf' created
gpg: WARNING: options in `/home/leo/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/home/leo/.gnupg/pubring.gpg' created
[0 [19:04][leo@archero Desktop]$ cat file.txt
file.txt      file.txt.gpg 
[0 [19:04][leo@archero Desktop]$ cat file.txt.gpg
���+���`�-9�����B�U���{[|-�Lzcz:̨��%N�m�S�pRL����][0 [19:05][leo@archero Desktop]$
[0 [19:05][leo@archero Desktop]$

Ahora si quieres descifrar dicho archivo:
gpg archivo.gpg

Ejemplo
Código:
[0 [19:05][leo@archero Desktop]$ gpg file.txt.gpg 
gpg: keyring `/home/leo/.gnupg/secring.gpg' created
gpg: CAST5 encrypted data
gpg: encrypted with 1 passphrase
File `file.txt' exists. Overwrite? (y/N) y
gpg: WARNING: message was not integrity protected
[0 [19:05][leo@archero Desktop]$