Because the project needs to be in the file transfer process to add decryption, so on the Internet to find the next plus decryption of the relevant introduction, the first use of RSA encryption and decryption algorithm, first use Rsaeuro toss half a day to compile the link stuck (compile error can not find out the reason), It is easy to find out how to use OpenSSL on the back of the web.
OpenSSL is a powerful cryptographic toolkit that integrates a wide range of cryptographic algorithms and utilities. It is easy to use the RSA algorithm to encrypt and decrypt, but only small data files (personal insights) can be processed, and other algorithms are needed to deal with large file data.
The relevant operation commands for the RSA algorithm can be consulted:
Http://www.cnblogs.com/aLittleBitCool/archive/2011/09/22/2185418.html
Now introduced under the use of OpenSSL AES algorithm to decrypt the big data files, I wrote a shell script, as follows
Encrypt encrypt.sh, where keyfile= "Enc.key" is a 16-character password file
#!/bin/sh# function: File encryption if [ $# -ne 2 ]then echo "Usage:$0 file name to encrypt File name after Encryption " echo " for example: $0 hello hello.en " exit 1fi# Flag is the same as the encrypted file name entered, and 1 is the same file name flag=0keyfile= "Enc.key" infile=$1outfile=$2if [ -f $INFILE ]then echo "Start encrypting $infile" else echo "error: File does not exist!!! exit 1fiif [ $INFILE = $OUTFILE ]then outfile=$2.tmp flag=1fi# Encrypting a file openssl enc -e -aes-128-cbc -kfile $ keyfile -in $INFILE -out $OUTFILEif [ $? -eq 0 ]then if [ flag -eq 1 ] then mv $OUTFILE $INFILE echo "Encryption complete! Generate the encrypted file as $infile "    ELSE&Nbsp; echo "Encryption complete! Generate Encrypted file for $outfile " fielse echo " Error: Encryption failed!!! "Fiexit 0
Decrypting decrpt.sh
#!/bin/sh# function: File decryption if [ $# -ne 2 ]then echo "usage:$0 file name to decrypt decrypted filename " echo " For example: $0 hello.en hello.de " exit 1fiflag=0keyfile= "Enc.key" infile=$1outfile=$2if [ -f $INFILE ]then echo "Start decrypting $infile" else echo "error: File does not exist!!! exit 1fiif [ $INFILE = $OUTFILE ]then outfile=$2.tmp flag=1fi# Decrypt the file openssl enc -d -aes-128-cbc -kfile $ keyfile -in $INFILE -out $OUTFILEif [ $? -eq 0 ]then if [ flag -eq 1 ] then mv $OUTFILE $INFILE echo "decryption complete! Generate the decrypted file as $infile " else echo "Decryption done! Generate decrypted file for $outfile " fielse echo " Error: Decryption failed!!! "Fiexit 0
For reference only, please correct me if there is a problem, thank you!
AES encryption and decryption of large files using OpenSSL under Unix