Encriptar e Desencriptar usando openssl base64 e validação md5sum

Encriptar

#!/bin/bash
# crypten - a script to encrypt files using openssl
PASS=senha.txt
FNAME=$1
date >> $FNAME.log
md5sum $FNAME >> $FNAME.log

if (( $# == 0 )); then
echo "crypten [ ... ]"
echo " - crypten is a script to encrypt file using aes256"
exit
fi
for FNAME in "$@"; do
openssl enc -aes-256-cbc -a -salt -in "$FNAME" -out "$FNAME.encriptado" -pass file:"$PASS"
done
date >> $FNAME.log

Desencriptar

#!/bin/bash
# crypten - a script to encrypt files using openssl
PASS=senha.txt
FNAME=$1
date >> $FNAME.log

if (( $# == 0 )); then
echo "crypten [ ... ]"
echo " - crypten is a script to encrypt file using aes256"
exit
fi
for FNAME in "$@"; do
openssl enc -aes-256-cbc -d -a -in "$FNAME" -out "$FNAME.desencriptado" -pass file:"$PASS"
done
date >> $FNAME.log
md5sum $FNAME.desencriptado >> $FNAME.log

Criar Senha

openssl rand -base64 4096 > senha.txt

======================================================
personalização do script crypten
http://linuxtidbits.wordpress.com/2009/01/12/encryptingdecrypting-a-file-easily-with-a-couple-bash-scripts/
======================================================

link sugerido:
https://www.madboa.com/geek/openssl/

Compartilhe...Share on FacebookShare on Google+Tweet about this on TwitterPin on PinterestShare on LinkedInShare on RedditEmail this to someone

Um comentário

  • Para Windows (arquivos de lote)

    Encriptar

    ECHO OFF

    COPY %1 %1.bak
    CLS

    openssl enc -aes-256-cbc -a -salt -in %1 -out %1.encriptado

    IF ERRORLEVEL 1 (
    ECHO.
    ECHO ********** UNABLE TO ENCRYPT FILE **********
    DEL %1.encriptado
    DEL %1.bak
    PAUSE
    ) ELSE (
    echo Encriptado com sucesso no arquivo: %1.enc
    IF NOT ERRORLEVEL 1 DEL %1.bak
    )

    ECHO ON

    Desencriptar

    ECHO OFF

    COPY %1 %1.bak
    CLS

    openssl enc -aes-256-cbc -d -a -in %1 -out %1.desencriptado

    IF ERRORLEVEL 1 (
    ECHO.
    ECHO ********** UNABLE TO DECRYPT FILE **********
    DEL %1.desencriptado
    DEL %1.bak
    PAUSE
    ) ELSE (
    IF NOT ERRORLEVEL 1 DEL %1.bak
    echo Desencriptado com sucesso no arquivo: %1.desencriptado
    )

    ECHO ON

    ===================================================================
    Adaptado de:
    http://www.codeproject.com/Tips/432905/Simple-File-Encryption-using-OpenSSL
    ===================================================================

Deixe uma resposta