Search code examples
unixencryptionopensslsasaes

encrypt file line by line using openssl on UNIX


I need to encrypt a file containing one CLIENT_ID by line.

When I use openssl enc -k jesuislacle -aes256 -base64 -e -in &_fidat/num_tie_dmp.csv -out &_fidat/decrypted_numtie.csv, I encrypt the whole file. But what I want is to encrypt line by line. i.e.

Original I have:

ABCDEC
FGHHIJ
KLMNOP
QRSTUV

What I want :

QHXrpv3ah0qEPBECCt1//PBKiugmWYMuE+WaA4r9Rgc#
nAca0Pb6bH1cQRfkO9wReY+X6dgl44BKE/nKSFBLM+o#
UjTJsoHoLAC0GeqqImxDXX9znUtd7dGm4VODZ+T7lvM#
dcU+H+jd9RZZqweDu1nnJDWMlKjxW2Hc+Q2uAW1tQfk#

For the moment, I launch this command X times for each ID. But I can have, more than 10000 ID to encrypt. It takes few hours to have the results. It's too much.

What's the best way. I'm on SAS 9.3, UNIX and I have to encrypt in AES 256 not MD5 (thank's to my DPO :-) )

Thanks for your help. Jérome


Solution

  • You can try this:

    while read line; do 
      echo "$line" | openssl enc -k jesuislacle -aes256 -base64 -e; 
    done <infile >outfile
    

    It reads all lines of the file one by one and encrypts it with the specified key.