#!/usr/bin/perl use strict; use Crypt::Twofish; use Crypt::CBC; my $key = "Super Secret Handshake"; my $cipher = new Crypt::CBC ($key, 'Twofish'); my $plaintext; my $ciphertext; # Open the plain text config file and read the data to encrypt. # print "Give me the server to connect :"; my $server=; chomp($server); print "Give me the user to login :"; my $login=; chomp($login); print "Give me the password to login :"; my $password=; chomp($password); open(PLAINTEXT,">Plain") || print "Error to write to the file"; print PLAINTEXT "$server\|$login\|$password\n"; local $/; $plaintext = ; close(PLAINTEXT); # Using our super-secret key write out the encrypted data. # open(CIPHERTEXT, "> Plain"); #EncryptedConfigFile $ciphertext = $cipher->encrypt($plaintext); $ciphertext = unpack("B*", $ciphertext); # convert the encrypted data into a string of "0"s and "1"s print CIPHERTEXT $ciphertext; close(CIPHERTEXT); ##</code><code>## #!/usr/bin/perl use strict; use Crypt::Twofish; use Crypt::CBC; # You'll need to use the same key that you used to encrypt the file. # my $key = "Super Secret Handshake"; my $cipher = new Crypt::CBC ($key, 'Twofish'); my $ciphertext; my $plaintext; { open(CIPHERTEXT, "Plain"); local $/; $ciphertext = <CIPHERTEXT>; close(CIPHERTEXT); } $ciphertext = pack("B*", $ciphertext); # convert a string of "0"s and "1"s into the binary encrypted string $plaintext = $cipher->decrypt($ciphertext); chomp($plaintext); my ($server, $username, $password) = split(/\|/, $plaintext); print STDOUT "Server: " . $server . "\n"; print STDOUT "Username: " . $username . "\n"; print STDOUT "Password: " . $password . "\n";