doc fixes
Karel Miko
10 years ago
208 | 208 | my $ct = dh_encrypt(\$buffer_containing_pub_key, $message); |
209 | 209 | #or |
210 | 210 | my $ct = dh_encrypt($pub_key_filename, $message, $hash_name); |
211 | ||
212 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
213 | ||
214 | Encryption works similar to the L<Crypt::PK::ECC> encryption whereas shared DH key is computed, and | |
215 | the hash of the shared key XOR'ed against the plaintext forms the ciphertext. | |
211 | 216 | |
212 | 217 | =head2 dh_decrypt |
213 | 218 | |
292 | 297 | |
293 | 298 | =head2 import_key |
294 | 299 | |
300 | Loads private or public key (exported by L</export_key>). | |
301 | ||
295 | 302 | $pk->import_key($filename); |
296 | 303 | #or |
297 | 304 | $pk->import_key(\$buffer_containing_key); |
309 | 316 | #or |
310 | 317 | my $ct = $pk->encrypt($message, $hash_name); |
311 | 318 | |
312 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest> | |
319 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
313 | 320 | |
314 | 321 | =head2 decrypt |
315 | 322 | |
323 | 330 | #or |
324 | 331 | my $signature = $priv->sign_message($message, $hash_name); |
325 | 332 | |
326 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest> | |
333 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
327 | 334 | |
328 | 335 | =head2 verify_message |
329 | 336 | |
332 | 339 | #or |
333 | 340 | my $valid = $pub->verify_message($signature, $message, $hash_name); |
334 | 341 | |
335 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest> | |
342 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
336 | 343 | |
337 | 344 | =head2 sign_hash |
338 | 345 | |
365 | 372 | |
366 | 373 | =head2 size |
367 | 374 | |
368 | my $size = $pk->is_private; | |
375 | my $size = $pk->size; | |
369 | 376 | # returns key size in bytes or undef if no key loaded |
370 | 377 | |
371 | 378 | =head2 key2hash |
374 | 381 | |
375 | 382 | # returns hash like this (or undef if no key loaded): |
376 | 383 | { |
377 | type => 0, | |
378 | size => 256, | |
379 | name => "DH-2048", | |
380 | x => "FBC1062F73B9A17BB8473A2F5A074911FA7F20D28FB...", | |
381 | y => "AB9AAA40774D3CD476B52F82E7EE2D8A8D40CD88BF4...", | |
382 | } | |
384 | type => 0, # integer: 1 .. private, 0 .. public | |
385 | size => 256, # integer: key size in bytes | |
386 | name => "DH-2048", # internal libtomcrypt name | |
387 | x => "FBC1062F73B9A17BB8473A2F5A074911FA7F20D28FB...", #private key | |
388 | y => "AB9AAA40774D3CD476B52F82E7EE2D8A8D40CD88BF4...", #public key | |
389 | } |
213 | 213 | |
214 | 214 | =head2 dsa_encrypt |
215 | 215 | |
216 | DSA based encryption. See method L</encrypt> below. | |
217 | ||
218 | my $pt = dsa_decrypt($priv_key_filename, $ciphertext); | |
219 | #or | |
220 | my $pt = dsa_decrypt(\$buffer_containing_priv_key, $ciphertext); | |
221 | ||
222 | Encryption works similar to the L<Crypt::PK::ECC> encryption whereas shared key is computed, and | |
216 | DSA based encryption as implemented by libtomcrypt. See method L</encrypt> below. | |
217 | ||
218 | my $ct = dsa_encrypt($pub_key_filename, $message); | |
219 | #or | |
220 | my $ct = dsa_encrypt(\$buffer_containing_pub_key, $message); | |
221 | #or | |
222 | my $ct = dsa_encrypt($pub_key_filename, $message, $hash_name); | |
223 | ||
224 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
225 | ||
226 | Encryption works similar to the L<Crypt::PK::ECC> encryption whereas shared DSA key is computed, and | |
223 | 227 | the hash of the shared key XOR'ed against the plaintext forms the ciphertext. |
224 | 228 | |
225 | 229 | =head2 dsa_decrypt |
226 | 230 | |
227 | DSA based decryption. See method L</decrypt> below. | |
231 | DSA based decryption as implemented by libtomcrypt. See method L</decrypt> below. | |
228 | 232 | |
229 | 233 | my $pt = dsa_decrypt($priv_key_filename, $ciphertext); |
230 | 234 | #or |
300 | 304 | |
301 | 305 | =head2 import_key |
302 | 306 | |
307 | Loads private or public key in DER or PEM format (password protected keys are not supported). | |
308 | ||
303 | 309 | $pk->import_key($filename); |
304 | 310 | #or |
305 | 311 | $pk->import_key(\$buffer_containing_key); |
320 | 326 | |
321 | 327 | my $pk = Crypt::PK::DSA->new($pub_key_filename); |
322 | 328 | my $ct = $pk->encrypt($message); |
329 | #or | |
330 | my $ct = $pk->encrypt($message, $hash_name); | |
331 | ||
332 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
323 | 333 | |
324 | 334 | =head2 decrypt |
325 | 335 | |
333 | 343 | #or |
334 | 344 | my $signature = $priv->sign_message($message, $hash_name); |
335 | 345 | |
336 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest> | |
346 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
337 | 347 | |
338 | 348 | =head2 verify_message |
339 | 349 | |
342 | 352 | #or |
343 | 353 | my $valid = $pub->verify_message($signature, $message, $hash_name); |
344 | 354 | |
345 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest> | |
355 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
346 | 356 | |
347 | 357 | =head2 sign_hash |
348 | 358 | |
363 | 373 | |
364 | 374 | =head2 size |
365 | 375 | |
366 | my $size = $pk->is_private; | |
376 | my $size = $pk->size; | |
367 | 377 | # returns key size in bytes or undef if no key loaded |
368 | 378 | |
369 | 379 | =head2 key2hash |
211 | 211 | |
212 | 212 | =head2 ecc_encrypt |
213 | 213 | |
214 | Elliptic Curve Diffie-Hellman (ECDH) encryption. | |
215 | ||
216 | ECCDH Encryption is performed by producing a random key, hashing it, and XOR'ing the digest against the plaintext. See method L</encrypt> below. | |
214 | Elliptic Curve Diffie-Hellman (ECDH) encryption as implemented by libtomcrypt. See method L</encrypt> below. | |
217 | 215 | |
218 | 216 | my $ct = ecc_encrypt($pub_key_filename, $message); |
219 | 217 | #or |
220 | 218 | my $ct = ecc_encrypt(\$buffer_containing_pub_key, $message); |
219 | #or | |
220 | my $ct = ecc_encrypt($pub_key_filename, $message, $hash_name); | |
221 | ||
222 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
223 | ||
224 | ECCDH Encryption is performed by producing a random key, hashing it, and XOR'ing the digest against the plaintext. | |
221 | 225 | |
222 | 226 | =head2 ecc_decrypt |
223 | 227 | |
224 | Elliptic Curve Diffie-Hellman (ECDH) decryption. See method L</decrypt> below. | |
228 | Elliptic Curve Diffie-Hellman (ECDH) decryption as implemented by libtomcrypt. See method L</decrypt> below. | |
225 | 229 | |
226 | 230 | my $pt = ecc_decrypt($priv_key_filename, $ciphertext); |
227 | 231 | #or |
303 | 307 | |
304 | 308 | =head2 import_key |
305 | 309 | |
310 | Loads private or public key in DER format (exported by L</export_key_der>). | |
311 | ||
306 | 312 | $pk->import_key($filename); |
307 | 313 | #or |
308 | 314 | $pk->import_key(\$buffer_containing_key); |
309 | 315 | |
310 | 316 | =head2 import_key_x963 |
311 | 317 | |
312 | ANSI X9.63 Import (public key only) - can load data exported by C<export_key_x963> | |
318 | ANSI X9.63 Import (public key only) - can load data exported by L</export_key_x963>. | |
313 | 319 | |
314 | 320 | $pk->import_key(\$buffer_containing_pub_key_ansi_x963); |
315 | 321 | |
329 | 335 | |
330 | 336 | my $pk = Crypt::PK::ECC->new($pub_key_filename); |
331 | 337 | my $ct = $pk->encrypt($message); |
338 | #or | |
339 | my $ct = $pk->encrypt($message, $hash_name); | |
340 | ||
341 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
332 | 342 | |
333 | 343 | =head2 decrypt |
334 | 344 | |
342 | 352 | #or |
343 | 353 | my $signature = $priv->sign_message($message, $hash_name); |
344 | 354 | |
345 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest> | |
355 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
346 | 356 | |
347 | 357 | =head2 verify_message |
348 | 358 | |
351 | 361 | #or |
352 | 362 | my $valid = $pub->verify_message($signature, $message, $hash_name); |
353 | 363 | |
354 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest> | |
364 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
355 | 365 | |
356 | 366 | =head2 sign_hash |
357 | 367 | |
384 | 394 | |
385 | 395 | =head2 size |
386 | 396 | |
387 | my $size = $pk->is_private; | |
397 | my $size = $pk->size; | |
388 | 398 | # returns key size in bytes or undef if no key loaded |
389 | 399 | |
390 | 400 | =head2 key2hash |
393 | 403 | |
394 | 404 | # returns hash like this (or undef if no key loaded): |
395 | 405 | { |
396 | type => 1, | |
397 | size => 32, | |
406 | type => 1, # integer: 1 .. private, 0 .. public | |
407 | size => 32, # integer: key (curve) size in bytes | |
408 | #curve parameters | |
398 | 409 | curve_name => "ECC-256", |
399 | 410 | curve_size => 32, |
400 | 411 | curve_B => "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B", |
402 | 413 | curve_Gy => "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5", |
403 | 414 | curve_order => "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", |
404 | 415 | curve_prime => "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", |
416 | #private key | |
405 | 417 | k => "A7F43ACD4A05D69AE4597E6E723EB5F1E9B9B7EAA51B6DE83CF36F9687B57DEE", |
418 | #public key point coordinates | |
406 | 419 | pub_x => "AB53ED5D16CE550BAAF16BA4F161332AAD56D63790629C27871ED515D4FC229C", |
407 | 420 | pub_y => "78FC34C6A320E22672A96EBB6DA48387A40541A3D7E5CFAE0D58A513E38C8888", |
408 | 421 | pub_z => "1", |
326 | 326 | |
327 | 327 | =head2 import_key |
328 | 328 | |
329 | Loads private or public key in DER or PEM format (password protected keys are not supported). | |
330 | ||
329 | 331 | $pk->import_key($priv_or_pub_key_filename); |
330 | 332 | #or |
331 | 333 | $pk->import_key(\$buffer_containing_priv_or_pub_key); |
429 | 431 | |
430 | 432 | =head2 size |
431 | 433 | |
432 | my $size = $pk->is_private; | |
434 | my $size = $pk->size; | |
433 | 435 | # returns key size in bytes or undef if no key loaded |
434 | 436 | |
435 | 437 | =head2 key2hash |