How to encrypt a file using Bash?











up vote
-2
down vote

favorite












I am trying to encrypt a test file I have and decrypt the file using a bash script.



I searched online and found I can use openssl and salt to do this.



I found the following code online:



FNAME=$1

if [[ -z "$FNAME" ]]; then
echo "cryptde <name of file>"
echo " - cryptde is a script to decrypt des3 encrypted files"
exit;
fi

openssl des3 -d -salt -in "$FNAME" -out "${FNAME%.[^.]*}"


How does it work?










share|improve this question
























  • What part do you not understand? Read the man page for each command.
    – user1133275
    Oct 11 '17 at 18:56















up vote
-2
down vote

favorite












I am trying to encrypt a test file I have and decrypt the file using a bash script.



I searched online and found I can use openssl and salt to do this.



I found the following code online:



FNAME=$1

if [[ -z "$FNAME" ]]; then
echo "cryptde <name of file>"
echo " - cryptde is a script to decrypt des3 encrypted files"
exit;
fi

openssl des3 -d -salt -in "$FNAME" -out "${FNAME%.[^.]*}"


How does it work?










share|improve this question
























  • What part do you not understand? Read the man page for each command.
    – user1133275
    Oct 11 '17 at 18:56













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I am trying to encrypt a test file I have and decrypt the file using a bash script.



I searched online and found I can use openssl and salt to do this.



I found the following code online:



FNAME=$1

if [[ -z "$FNAME" ]]; then
echo "cryptde <name of file>"
echo " - cryptde is a script to decrypt des3 encrypted files"
exit;
fi

openssl des3 -d -salt -in "$FNAME" -out "${FNAME%.[^.]*}"


How does it work?










share|improve this question















I am trying to encrypt a test file I have and decrypt the file using a bash script.



I searched online and found I can use openssl and salt to do this.



I found the following code online:



FNAME=$1

if [[ -z "$FNAME" ]]; then
echo "cryptde <name of file>"
echo " - cryptde is a script to decrypt des3 encrypted files"
exit;
fi

openssl des3 -d -salt -in "$FNAME" -out "${FNAME%.[^.]*}"


How does it work?







bash encryption






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 at 14:18









Rui F Ribeiro

38.3k1475126




38.3k1475126










asked Oct 11 '17 at 17:48









Allen

11




11












  • What part do you not understand? Read the man page for each command.
    – user1133275
    Oct 11 '17 at 18:56


















  • What part do you not understand? Read the man page for each command.
    – user1133275
    Oct 11 '17 at 18:56
















What part do you not understand? Read the man page for each command.
– user1133275
Oct 11 '17 at 18:56




What part do you not understand? Read the man page for each command.
– user1133275
Oct 11 '17 at 18:56










1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted











  1. FNAME=$1


This assigns the first parameter to FNAME




  1. if [[ -z "$FNAME" ]]; then


If the string $FNAME is zero in length, then echo the help output and exit




  1. openssl des3 -d -salt -in "$FNAME" -out "${FNAME%.[^.]*}"


This line runs the openssl command's des3 module (man des3) takes $FNAME as input file name, then writes output to $FNAME without a .extension. This final argument is a regular expression that strips the extension off (.[NOT .]any number of times.






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f397537%2fhow-to-encrypt-a-file-using-bash%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted











    1. FNAME=$1


    This assigns the first parameter to FNAME




    1. if [[ -z "$FNAME" ]]; then


    If the string $FNAME is zero in length, then echo the help output and exit




    1. openssl des3 -d -salt -in "$FNAME" -out "${FNAME%.[^.]*}"


    This line runs the openssl command's des3 module (man des3) takes $FNAME as input file name, then writes output to $FNAME without a .extension. This final argument is a regular expression that strips the extension off (.[NOT .]any number of times.






    share|improve this answer

























      up vote
      0
      down vote



      accepted











      1. FNAME=$1


      This assigns the first parameter to FNAME




      1. if [[ -z "$FNAME" ]]; then


      If the string $FNAME is zero in length, then echo the help output and exit




      1. openssl des3 -d -salt -in "$FNAME" -out "${FNAME%.[^.]*}"


      This line runs the openssl command's des3 module (man des3) takes $FNAME as input file name, then writes output to $FNAME without a .extension. This final argument is a regular expression that strips the extension off (.[NOT .]any number of times.






      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted







        1. FNAME=$1


        This assigns the first parameter to FNAME




        1. if [[ -z "$FNAME" ]]; then


        If the string $FNAME is zero in length, then echo the help output and exit




        1. openssl des3 -d -salt -in "$FNAME" -out "${FNAME%.[^.]*}"


        This line runs the openssl command's des3 module (man des3) takes $FNAME as input file name, then writes output to $FNAME without a .extension. This final argument is a regular expression that strips the extension off (.[NOT .]any number of times.






        share|improve this answer













        1. FNAME=$1


        This assigns the first parameter to FNAME




        1. if [[ -z "$FNAME" ]]; then


        If the string $FNAME is zero in length, then echo the help output and exit




        1. openssl des3 -d -salt -in "$FNAME" -out "${FNAME%.[^.]*}"


        This line runs the openssl command's des3 module (man des3) takes $FNAME as input file name, then writes output to $FNAME without a .extension. This final argument is a regular expression that strips the extension off (.[NOT .]any number of times.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 11 '17 at 18:56









        Ed Neville

        1,13157




        1,13157






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f397537%2fhow-to-encrypt-a-file-using-bash%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Accessing regular linux commands in Huawei's Dopra Linux

            Can't connect RFCOMM socket: Host is down

            Kernel panic - not syncing: Fatal Exception in Interrupt