| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use FFI::Platypus 2.00; |
| 4 |
use FFI::Platypus::Buffer qw( buffer_to_scalar ); |
| 5 |
use YAML (); |
| 6 |
|
| 7 |
my $ffi = FFI::Platypus->new( |
| 8 |
api => 2, |
| 9 |
lib => './xor_cipher.so', |
| 10 |
); |
| 11 |
|
| 12 |
$ffi->attach( string_crypt_free => ['opaque'] ); |
| 13 |
|
| 14 |
$ffi->attach( string_crypt => ['string','int','string'] => 'opaque' => sub{ |
| 15 |
my($xsub, $input, $key) = @_; |
| 16 |
my $ptr = $xsub->($input, length($input), $key); |
| 17 |
my $output = buffer_to_scalar $ptr, length($input); |
| 18 |
string_crypt_free($ptr); |
| 19 |
return $output; |
| 20 |
}); |
| 21 |
|
| 22 |
my $orig = "hello world"; |
| 23 |
my $key = "foobar"; |
| 24 |
|
| 25 |
print YAML::Dump($orig); |
| 26 |
my $encrypted = string_crypt($orig, $key); |
| 27 |
print YAML::Dump($encrypted); |
| 28 |
my $decrypted = string_crypt($encrypted, $key); |
| 29 |
print YAML::Dump($decrypted); |