Crypt-Cryptoki

 view release on metacpan or  search on metacpan

t/cryptoki.t  view on Meta::CPAN


my $t_private = Crypt::Cryptoki::Template::RSAPrivateKey->new(
	token => 1,
	decrypt => 1,
	sign => 1,
	unwrap => 1,
	label => 'test',
	id => pack('C*', 0x01, 0x02, 0x03)
);

my ( $public_key, $private_key ) = $session->generate_key_pair($t_public,$t_private);

try {
	my $plain_text = 'plain text';
	my ( $encrypted_text_ref, $len ) = $public_key->encrypt(\$plain_text, length($plain_text));

	( $encrypted_text_ref ) = $private_key->decrypt($encrypted_text_ref, $len);
	diag $$encrypted_text_ref;

	diag explain $public_key->get_attributes(1);
	diag $public_key->export_as_string;

	diag explain $private_key->get_attributes(1);

} catch { diag $_; 0 };

ok $public_key->destroy;
ok $private_key->destroy;

done_testing();

t/openssl.t  view on Meta::CPAN

    [ CKA_TOKEN,           pack('C',TRUE) ],
    [ CKA_ENCRYPT,         pack('C',TRUE) ],
    [ CKA_VERIFY,          pack('C',TRUE) ],
    [ CKA_WRAP,            pack('C',TRUE) ],
    [ CKA_MODULUS_BITS,    pack('Q',4096) ],
    [ CKA_PUBLIC_EXPONENT, pack('C*', 0x01, 0x00, 0x01) ],
    [ CKA_LABEL,    	   'test_pub' ],
	[ CKA_ID, 			   pack('C*', 0x01, 0x02, 0x03) ],
];

my $private_key_template = [
    [ CKA_CLASS,      pack('Q',CKO_PRIVATE_KEY) ],
    [ CKA_KEY_TYPE,   pack('Q',CKK_RSA) ],
    [ CKA_TOKEN,      pack('C',TRUE) ],
    [ CKA_PRIVATE,    pack('C',TRUE) ],
    [ CKA_SENSITIVE,  pack('C',TRUE) ],
    [ CKA_DECRYPT,    pack('C',TRUE) ],
    [ CKA_SIGN,       pack('C',TRUE) ],
    [ CKA_UNWRAP,     pack('C',TRUE) ],
    [ CKA_LABEL,      'test' ],
	[ CKA_ID, 		  pack('C*', 0x04, 0x05, 0x06) ],
];

my $private_key = -1;
my $public_key = -1;

is rv_to_str($f->C_GenerateKeyPair(
	$session, 
	[ CKM_RSA_PKCS_KEY_PAIR_GEN, NULL_PTR, 0 ], 
	$public_key_template,
    $private_key_template,
	$public_key, 
	$private_key
)), 'CKR_OK', 'C_GenerateKeyPair';

my $get_attributes_template = [
    [ CKA_MODULUS, '' ],
    [ CKA_PUBLIC_EXPONENT, '' ],
];

is rv_to_str($f->C_GetAttributeValue(
	$session,
	$public_key,

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.386 second using v1.00-cache-2.02-grep-82fe00e-cpan-2cc899e4a130 )