Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Encryption, Decryption & Password Protection

by Bugz (Acolyte)
on Dec 15, 2014 at 22:27 UTC ( #1110413=perlquestion: print w/replies, xml ) Need Help??

Bugz has asked for the wisdom of the Perl Monks concerning the following question:

I have three part problem: 1. I'd like to encrypt a file and store it and decrypt it when I need to use it. How can i do that? 2. I need to password protect access my perl script which does the encryption & decryption so that no one can open it and read what's in without a password 3. Unless the right password it provided no one can execute my perl script. Can you please provide examples of how I can do this?
  • Comment on Encryption, Decryption & Password Protection

Replies are listed 'Best First'.
Re: Encryption, Decryption & Password Protection
by RonW (Parson) on Dec 15, 2014 at 23:19 UTC

    The example in the docs for Crypt::CBC should serve your encryption needs. I would suggest using the Rijndael algorithm (supplied by Crypt::Rijndael)

    You don't need to password protect your encryption/decryption script. Just have your script ask you to type in your encryption key.

      Thanks, I will look up the Crypt:CBC module.
Re: Encryption, Decryption & Password Protection
by CountZero (Bishop) on Dec 16, 2014 at 07:08 UTC
    That doesn't seem to be a Perl-problem, but rather something you want to solve on the level of your OS.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re: Encryption, Decryption & Password Protection
by sweetblood (Prior) on Dec 16, 2014 at 00:19 UTC
    It appears after looking at other questions you have asked as well as this one that you have a bad habit of not providing any code indicating the attempts you have made and the problems you have been having. Rather than asking for examples of how you can do this, show us what you have tried. It appears that you are expecting us to write code for you based on your requirements, perlmonks is not a code writing service.

    Sweetblood

      That's not the intention. I was more interested in understanding work flow and modules to be used. I did do some initial homework and saw some examples and did not believe it fulfilled the requirement for me. So I thought of asking the monks for their advise on how do i go about doing this.
Re: Encryption, Decryption & Password Protection
by hardburn (Abbot) on Dec 16, 2014 at 21:34 UTC

    GnuPG can be used to encrypt files. Is there a particular reason you want to use Perl for this?

    More generally, I get the impression that you don't have a lot of experience with encryption (not an insult, just a statement of fact). That is a very good sign that you should be using premade solutions, not trying to come up with your own.


    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

      Thank you for your response. I haven't done any encryption till now so you are right in assessing the situation. No offense taken. I am okay with pre-made solutions and will look at GnuPG But learning about how it's done and how things work underneath the hood was the minor goal of this effort.
Re: Encryption, Decryption & Password Protection
by cavac (Curate) on Dec 17, 2014 at 18:55 UTC

    To your second point:
    If the user is still supposed to be able to execute the Perl script, you can't really protect it. Obfuscate, yes, but securely encrypt, no.

    To be clear on the subject of encryption: If you choose a good encryption method and protect the encrypted file(s) with a good key (depending on the method somewhere between 128 and ~8000 bits or so), it doesn't matter if the encryption method is readable to all. Actually, using an open sourced, well known encryption method has a better chance of actually being secure.

    If you are new to encryption, you might want to read a few books about it. I personally liked "The Code Book: The Science of Secrecy from Ancient Egypt to Quantum Cryptography" by Simon Singh, ISBN 0-385-49531-5. Also, you might like to read Bruce Schneier's blog and others to keep up to date.

    "I know what i'm doing! Look, what could possibly go wrong? All i have to pull this lever like so, and then press this button here like ArghhhhhaaAaAAAaaagraaaAAaa!!!"
Re: Encryption, Decryption & Password Protection
by planetscape (Chancellor) on Dec 18, 2014 at 12:04 UTC

    If I were you, I'd have a look at Cryptopad 3.10 and see how the author does things. For instance, he does NOT store passwords in his script, and therefore has no need to obfuscate the source.

    HTH,

    planetscape

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1110413]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2019-10-16 22:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?