Problem of encrypt openssl RC4

Hi Guys sorry about post the code in portuguese but now i fix almost parts of code. now i can encryped and decryped the files but have a small problem. When not writte nathing generate automatically a random cypher but after the value of this cypher not appear igual than variable $saved_key. And used this value modifacate for decrypt file and i can see nathing because not use the correct cypher. How can fix this?

This my code modificate;

 

file_key="cypher.txt"
saved_key=$(cat cypher.txt)

menu_Start(){
clear_screen
echo ---------------------------------------------------
echo                  Manufactory RC4 OpenSSL
echo ---------------------------------------------------
echo ""
echo 1 - RC4 little used
echo Insert the cypher most be used:

read option_menu

case $option_menu in
1) menu;;
esac

}


menu(){
clear_screen

echo "REVERSE CRYPTO 4"
echo ""
echo "1 -> Encrypt"
echo "2 -> Decrypt"
echo "3 -> go back last menu"
echo "Choise the number of options:"

read option

case $option in
0);;	
1) encrypt_RC4 ;;
2) decrypt_RC4 ;;
esac
}

encrypt_RC4() {
clear_screen

name="RC4"
echo -n "Insert the cypher hex that you want created:"; read CYPHER
echo $CYPHER > $file_key

# Problem in this part when generated the cypher

if [[ -z "$CYPHER" ]]; then
echo $(openssl rand -hex 8) > $file_key # generated the cypher principal ex: abcdc34ba
fi
#--------------------------------------------------------------------------------------------------------
cat $file_key

echo -n "Insert the name of file for encrypted:"; read IN_FILE   
echo -n "Insert the name of file for out:"; read OUT_FILE
if [[ -z "$IN_FILE" ]]; then
   echo "The file was cypher"	
fi

case $option_menu in
1) algorithm_encryptRC4 ;;
esac

echo "The cypher used is: " $name
echo "The key of cypher is: " $saved_key # show other random cypher ex:abc45aec and used this value.
echo "The file created was:" $OUT_FILE
echo "The file exclued is:" $IN_FILE
}


decrypt_RC4() {
clear_screen

echo -n "Insert the name of the file encryped:"; read OUT_FILE
echo -n "Insert the name of the file for decrypting:"; read IN_FILE

if [[ -z "$OUT_FILE" ]]; then
	echo 
fi

case $option_menu in
1) algorithm_decryptRC4 ;;
esac


echo "The key used is: " $saved_key
echo "The file created was: " $IN_FILE
echo "The file exclued was: " $OUT_FILE	

}


algorithm_encryptRC4(){
openssl enc -rc4 -e -K "$saved_key" -in "$IN_FILE.txt" -out "$OUT_FILE.rc4"
}

algorithm_decryptRC4(){	
openssl enc -rc4 -d -K "$saved_key" -in "$OUT_FILE.rc4" -out "$IN_FILE.txt"
}

clear_screen(){
clear
}

menu_Start

Normally, we only accept posts (and code) in the English language.

Thanks for posting, but it is not likely you will get a reply with most of your code, including your variable names, in Galician.

I have to second Neo - your code is nearly incomprehensible. Still I find that you read a cipher and place it into the "chave.txt" file regardless of it being empty or not, thus overwriting or even eliminating the file's contents. And, defining "chave_guardada" at the script's start may not help, either. You may want to untangle the logic flow of your script.

1 Like