I am running up against a wall and hitting it hard. I am needing to encrypt fields and not he entire file for data upload. I then need to use that encrypted field as a key in a system and then when extracted, I need to be able to decypt it. Below are sample lines from a fake text creator to illustrate my quandary."

customerid registered_date first_name last_name address city state zip age primary_email
689-08-2317 1518973472 Sascha Urian 85 Sunbrook Road San Antonio Texas 78250 55 surian0@archive.org
201-25-0510 1515436776 Gilbertine Impy 3136 Thierer Trail Mc Keesport Pennsylvania 15134 49 gimpy1@edublogs.org
616-54-5114 1518645090 Christabella Gunther 4 Autumn Leaf Junction Chicago Illinois 60619 26 cgunther2@nature.com

I would need to read in the file, encrypt column 1 & 9, then output the file in the same format but with those values having encrypted values. I may be going down the wrong path here and really need a hash process but I have exhausted my working brain cells at this point and need some help. The end format would look like this below.

customerid registered_date first_name last_name address city state zip age primary_email
$#diDse*eES 1518973472 Sascha Urian 85 Sunbrook Road San Antonio Texas 78250 55 weSIDUsae34@#$%%#@@
eSDE#24DSET 1515436776 Gilbertine Impy 3136 Thierer Trail Mc Keesport Pennsylvania 15134 49 sdies#@SERUSEeset
OEDUse#@#$2 1518645090 Christabella Gunther 4 Autumn Leaf Junction Chicago Illinois 60619 26 mvxosef@#w32553S

I have been trying to modify this base code

#!/usr/bin/perl use strict; use Crypt::CBC; #unless (scalar @ARGV == 3) { # #die "Usage: $0 encrypt|decrypt|en|de \$mysecretkey \$file_to_den +crypt"; #} #my $type = shift @ARGV; #my $key = shift @ARGV; #my $file = shift @ARGV; my $type = "de"; my $key = "12345"; my $file = "C:\\perlinputfiletest\\fakedata.txt.encrypt"; die "The first ARGV should be one of de, en, encrypt, decrypt" if ($ty +pe !~ /^(en|de)(crypt)?$/); die "the file $file is not existence" unless (-f $file); my $DEBUG = 1; print "type is $type, key is $key, file is $file\n" if $DEBUG; my $cipher = Crypt::CBC->new( -key => $key, -cipher => 'Blowfish' ); local $/; open(FH, $file) or die $!; flock(FH, 2); my $data = <FH>; close(FH); my ($save_data, $save_file); if ($type =~ /^en(crypt)?$/) { $save_data = $cipher->encrypt($data); $save_file = $file . '.encrypt'; } else { $save_data = $cipher->decrypt($data); $save_file = $file . '.decrypt'; } open(FH, '>', $save_file) or die $!; print FH $save_data; close(FH); if (-e $save_file) { print "$type file $file to $save_file OK\n"; } else { print "failed without reason\n"; }


In reply to Using Cypher::CBC to encrypt fields in a file - Need Monk Help by perlc1ph3r

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.