Padre-Plugin-Encrypt

 view release on metacpan or  search on metacpan

lib/Padre/Plugin/Encrypt.pm  view on Meta::CPAN


sub get_layout {
	my ($type) = @_;

	my @types = ( 'encrypt', 'decrypt' );
	my @layout = (
		[   [ 'Wx::StaticText', undef, 'Type:' ],
			[ 'Wx::ComboBox', '_type_', $type, \@types ],
		],
		[   [ 'Wx::StaticText', undef,           'Private key:' ],
			[ 'Wx::TextCtrl',   '_private_key_', '' ],
		],
		[   [ 'Wx::Button', '_ok_',     Wx::wxID_OK ],
			[ 'Wx::Button', '_cancel_', Wx::wxID_CANCEL ],
		],
	);
	return \@layout;
}

sub dencrypt {
	my ( $self, $type ) = @_;

lib/Padre/Plugin/Encrypt.pm  view on Meta::CPAN

	my $dialog = Padre::Wx::Dialog->new(
		parent => $main,
		title  => lcfirst $type,
		layout => $layout,
		width  => [ 100, 100 ],
	);

	$dialog->{_widgets_}{_ok_}->SetDefault;
	Wx::Event::EVT_BUTTON( $dialog, $dialog->{_widgets_}{_ok_},     \&ok_clicked );
	Wx::Event::EVT_BUTTON( $dialog, $dialog->{_widgets_}{_cancel_}, \&cancel_clicked );
	$dialog->{_widgets_}{_private_key_}->SetFocus;

	$dialog->Show(1);
}

sub cancel_clicked {
	my ( $dialog, $event ) = @_;

	$dialog->Destroy;

	return;
}

sub ok_clicked {
	my ( $dialog, $event ) = @_;

	my $main = Padre->ide->wx->main;

	my $data = $dialog->get_data;
	$dialog->Destroy;

	my $private_key = $data->{_private_key_};
	unless ( length($private_key) ) {
		$main->message( Wx::gettext("Private key is required") );
		return;
	}

	my $type = $data->{_type_};

	my $doc = $main->current->document;
	return unless $doc;
	my $code = $doc->text_get;

	require Crypt::CBC;
	my $cipher = Crypt::CBC->new(
		-key    => $private_key,
		-cipher => 'Blowfish'
	);

	eval {
		if ( $type eq 'encrypt' )
		{

			# Encrypt
			$code = $cipher->encrypt_hex($code);
		} else {



( run in 0.233 second using v1.01-cache-2.11-cpan-a5abf4f5562 )