Disclaimer: embedding passwords in scripts (or most things, for that matter) where they must be converted back into 'plaintext' is insecure, period. No amount of clever encryption or hoop-jumping can make it secure.


For reasons not worth getting into, we (at company X) end up embedding passwords in admin scripts a lot. We're finally getting around to trying to obfuscate the passwords some. It should be easy to convert existing scripts, etc.

So I took a spoonful of Acme::Bleach, a pinch of Exporter and here's what I got.

use My::Acme::Clutter qq[( test => 45, foo => 'bar')];

once cluttered (i.e. run once) becomes:

use My::Acme::Clutter '`282074657374203d3e2034352c20666f6f203d3e202762 +61722729';

It's a very simple encrypt/decrypt, but meets our level of "difficult". I need to add some error checks. And I'd like to use Exporter, but I couldn't get export_to_level to work :?

Besides that, all opinions desired!

package My::Acme::Clutter; use 5.006; sub encrypt { my $return; for ( split(//,shift) ) { $return .= sprintf("%02x",ord($_)); } return $return; } sub decrypt { my $return; for ( $_[0] =~ /.{2}/g ) { $return .= chr( hex $_ ); } return $return; } sub import { my $pkg = shift; my $callpkg = (caller)[0]; my $string = shift; if ($string =~ s/^`//) { $string = decrypt($string); } else { my $clutter = encrypt($string); open 0 or print "Can't clutter '$0'\n"; (my $file = join "", <0>) =~ s{^\s*use\s+My::Acme::Clutter.*?;\n}{use My::Acme::Clutter ' +`$clutter';}m; open 0, ">$0" or print "Cannot clutter '$0'\n" and exit; print {0} $file and exit; } # turn the string into a hash my %args = eval $string; # finally, do the import; for my $var (keys %args) { ${"${callpkg}::$var"} = $args{$var}; } } 1;
--Solo
--
There's no mystical energy field that controls my destiny. It's all a lot of simple tricks and nonsense.


In reply to Embed passwords (Acme::Clutter idea) by Solo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.