Crypto API¶
spindlex.crypto ¶
SSH Cryptography Module
Provides pluggable cryptographic backend abstraction with support for modern ciphers, key exchange algorithms, and cryptographic operations.
Classes¶
CipherSuite ¶
SSH cipher suite implementation.
Manages cipher algorithms, key exchange methods, and MAC algorithms with preference for modern, secure cryptographic primitives.
Source code in spindlex/crypto/ciphers.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
Methods:¶
__init__(crypto_backend=None) ¶
Initialize cipher suite with secure defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crypto_backend | Optional[CryptoBackend] | Cryptographic backend to use (defaults to CryptographyBackend) | None |
Source code in spindlex/crypto/ciphers.py
get_cipher_info(algorithm) ¶
Get cipher information for specified algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm | str | Cipher algorithm name | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary with key_len and iv_len properties |
Raises:
| Type | Description |
|---|---|
CryptoException | If algorithm is unsupported |
Source code in spindlex/crypto/ciphers.py
get_mac_info(algorithm) ¶
Get MAC information for specified algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm | str | MAC algorithm name | required |
Returns:
| Type | Description |
|---|---|
dict[str, int] | Dictionary with key_len and digest_len properties |
Raises:
| Type | Description |
|---|---|
CryptoException | If algorithm is unsupported |
Source code in spindlex/crypto/ciphers.py
negotiate_algorithms(client_algorithms, server_algorithms) ¶
Negotiate algorithms between client and server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client_algorithms | dict[str, list[str]] | Client's supported algorithms | required |
server_algorithms | dict[str, list[str]] | Server's supported algorithms | required |
Returns:
| Type | Description |
|---|---|
dict[str, str] | Dictionary of negotiated algorithms |
Raises:
| Type | Description |
|---|---|
CryptoException | If no compatible algorithms found |
Source code in spindlex/crypto/ciphers.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
CryptoBackend ¶
Bases: Protocol
Cryptographic backend interface.
Defines the interface for pluggable cryptographic backends to support different crypto libraries and implementations.
Source code in spindlex/crypto/backend.py
Methods:¶
chacha20_poly1305_decrypt_body(key_64, seq_num, enc_length, enc_body, tag) ¶
Verify Poly1305 tag and decrypt the packet body.
chacha20_poly1305_decrypt_length(key_64, seq_num, enc_length) ¶
Decrypt the 4-byte length field using chacha20-poly1305@openssh.com.
chacha20_poly1305_encrypt(key_64, seq_num, length_bytes, body_bytes) ¶
Encrypt an SSH packet using chacha20-poly1305@openssh.com.
compute_mac(algorithm, key, data) ¶
create_cipher(algorithm, key, iv) ¶
decrypt(algorithm, key, iv, data) ¶
decrypt_length(algorithm, key, iv, data) ¶
derive_key(algorithm, shared_secret, exchange_hash, session_id, key_type, key_length) ¶
Derive encryption/MAC keys from shared secret.
encrypt(algorithm, key, iv, data) ¶
generate_random(length) ¶
CryptographyBackend ¶
Cryptography library backend implementation.
Implements CryptoBackend interface using the Python cryptography library for modern, secure cryptographic operations.
Source code in spindlex/crypto/backend.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
Methods:¶
__init__() ¶
compute_mac(algorithm, key, data) ¶
Compute MAC using specified algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm | str | MAC algorithm name | required |
key | bytes | MAC key | required |
data | bytes | Data to authenticate | required |
Returns:
| Type | Description |
|---|---|
bytes | MAC digest |
Raises:
| Type | Description |
|---|---|
CryptoException | If MAC computation fails |
Source code in spindlex/crypto/backend.py
create_cipher(algorithm, key, iv) ¶
Create cipher instance for streaming operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm | str | Cipher algorithm name | required |
key | bytes | Encryption/decryption key | required |
iv | bytes | Initialization vector | required |
Returns:
| Type | Description |
|---|---|
Any | Cipher instance for streaming operations |
Raises:
| Type | Description |
|---|---|
CryptoException | If cipher creation fails |
Source code in spindlex/crypto/backend.py
decrypt(algorithm, key, iv, data) ¶
Decrypt data using specified cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm | str | Cipher algorithm name | required |
key | bytes | Decryption key | required |
iv | bytes | Initialization vector or nonce | required |
data | bytes | Data to decrypt | required |
Returns:
| Type | Description |
|---|---|
bytes | Decrypted data |
Raises:
| Type | Description |
|---|---|
CryptoException | If decryption fails or algorithm unsupported |
Source code in spindlex/crypto/backend.py
decrypt_length(algorithm, key, iv, data) ¶
Decrypt only the length field for ciphers that encrypt it.
For AES-CTR (the only cipher currently supported), the full packet including the length field is decrypted together, so this method is not used. It is retained as a hook for future CBC-mode support where the 4-byte length must be decrypted before knowing how much payload to read from the socket.
Returns:
| Type | Description |
|---|---|
bytes |
|
Source code in spindlex/crypto/backend.py
derive_key(algorithm, shared_secret, exchange_hash, session_id, key_type, key_length) ¶
Derive encryption/MAC keys from shared secret using SSH key derivation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm | str | Hash algorithm for key derivation | required |
shared_secret | bytes | Shared secret K - MUST be mpint-encoded per RFC 4253 §7.2, i.e. a 4-byte big-endian length prefix followed by the minimal two's-complement big-endian representation of K (with a leading 0x00 byte if the MSB is set). Pass write_mpint(K) from protocol.utils. | required |
exchange_hash | bytes | Hash of key exchange | required |
session_id | bytes | Session identifier | required |
key_type | bytes | Key type identifier (A, B, C, D, E, F) | required |
key_length | int | Required key length | required |
Returns:
| Type | Description |
|---|---|
bytes | Derived key |
Raises:
| Type | Description |
|---|---|
CryptoException | If key derivation fails or shared_secret is not mpint-encoded |
Source code in spindlex/crypto/backend.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
encrypt(algorithm, key, iv, data) ¶
Encrypt data using specified cipher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm | str | Cipher algorithm name | required |
key | bytes | Encryption key | required |
iv | bytes | Initialization vector or nonce | required |
data | bytes | Data to encrypt | required |
Returns:
| Type | Description |
|---|---|
bytes | Encrypted data |
Raises:
| Type | Description |
|---|---|
CryptoException | If encryption fails or algorithm unsupported |
Source code in spindlex/crypto/backend.py
generate_random(length) ¶
Generate cryptographically secure random bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length | int | Number of random bytes to generate | required |
Returns:
| Type | Description |
|---|---|
bytes | Cryptographically secure random bytes |
Raises:
| Type | Description |
|---|---|
CryptoException | If random generation fails |
Source code in spindlex/crypto/backend.py
hash_data(algorithm, data) ¶
Hash data using specified algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm | str | Hash algorithm name (sha256, sha384, sha512) | required |
data | bytes | Data to hash | required |
Returns:
| Type | Description |
|---|---|
bytes | Hash digest |
Raises:
| Type | Description |
|---|---|
CryptoException | If hashing fails or algorithm unsupported |
Source code in spindlex/crypto/backend.py
ECDSAKey ¶
Bases: PKey
ECDSA SSH key implementation.
Implements ecdsa-sha2-nistp256 key type using NIST P-256 curve.
Source code in spindlex/crypto/pkey.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 | |
Attributes¶
algorithm_name property ¶
Get SSH algorithm name.
Methods:¶
__init__(crypto_backend=None, curve_name='nistp256') ¶
Initialize ECDSA key with specified curve.
Source code in spindlex/crypto/pkey.py
generate(key_type='ecdsa', bits=256, *args, **kwargs) classmethod ¶
Generate a new ECDSA key pair (default P-256).
Source code in spindlex/crypto/pkey.py
get_public_key_bytes() ¶
Get ECDSA public key in SSH wire format.
Returns:
| Type | Description |
|---|---|
bytes | Public key bytes in SSH wire format |
Raises:
| Type | Description |
|---|---|
CryptoException | If no key loaded |
Source code in spindlex/crypto/pkey.py
load_private_key(key_data, password=None) ¶
Load ECDSA private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data | bytes | Private key data (PEM or OpenSSH format) | required |
password | Optional[bytes] | Optional password for encrypted keys | None |
Raises:
| Type | Description |
|---|---|
CryptoException | If key loading fails |
Source code in spindlex/crypto/pkey.py
load_public_key(key_data) ¶
Load ECDSA public key from SSH wire format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data | bytes | Public key data in SSH wire format | required |
Raises:
| Type | Description |
|---|---|
CryptoException | If key loading fails |
Source code in spindlex/crypto/pkey.py
save_to_file(filename, password=None) ¶
Save ECDSA private key to file.
Source code in spindlex/crypto/pkey.py
sign(data) ¶
Sign data with ECDSA private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | bytes | Data to sign | required |
Returns:
| Type | Description |
|---|---|
bytes | Signature bytes in SSH format |
Raises:
| Type | Description |
|---|---|
CryptoException | If signing fails or no private key |
Source code in spindlex/crypto/pkey.py
verify(signature, data) ¶
Verify ECDSA signature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signature | bytes | Signature bytes in SSH format | required |
data | bytes | Original data that was signed | required |
Returns:
| Type | Description |
|---|---|
bool | True if signature is valid, False otherwise |
Source code in spindlex/crypto/pkey.py
Ed25519Key ¶
Bases: PKey
Ed25519 SSH key implementation.
Implements ssh-ed25519 key type using Ed25519 signature algorithm.
Source code in spindlex/crypto/pkey.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
Attributes¶
algorithm_name property ¶
Get SSH algorithm name.
Methods:¶
generate(key_type='ed25519', bits=256, *args, **kwargs) classmethod ¶
Generate a new Ed25519 key pair.
Source code in spindlex/crypto/pkey.py
get_public_key_bytes() ¶
Get Ed25519 public key in SSH wire format.
Returns:
| Type | Description |
|---|---|
bytes | Public key bytes in SSH wire format |
Raises:
| Type | Description |
|---|---|
CryptoException | If no key loaded |
Source code in spindlex/crypto/pkey.py
load_private_key(key_data, password=None) ¶
Load Ed25519 private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data | bytes | Private key data (PEM or OpenSSH format) | required |
password | Optional[bytes] | Optional password for encrypted keys | None |
Raises:
| Type | Description |
|---|---|
CryptoException | If key loading fails |
Source code in spindlex/crypto/pkey.py
load_public_key(key_data) ¶
Load Ed25519 public key from SSH wire format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data | bytes | Public key data in SSH wire format | required |
Raises:
| Type | Description |
|---|---|
CryptoException | If key loading fails |
Source code in spindlex/crypto/pkey.py
save_to_file(filename, password=None) ¶
Save Ed25519 private key to file.
Source code in spindlex/crypto/pkey.py
sign(data) ¶
Sign data with Ed25519 private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | bytes | Data to sign | required |
Returns:
| Type | Description |
|---|---|
bytes | Signature bytes in SSH format |
Raises:
| Type | Description |
|---|---|
CryptoException | If signing fails or no private key |
Source code in spindlex/crypto/pkey.py
verify(signature, data) ¶
Verify Ed25519 signature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signature | bytes | Signature bytes in SSH format | required |
data | bytes | Original data that was signed | required |
Returns:
| Type | Description |
|---|---|
bool | True if signature is valid, False otherwise |
Source code in spindlex/crypto/pkey.py
PKey ¶
Base class for SSH public keys.
Provides common interface for different public key types with support for loading, saving, signing, verification, and fingerprinting.
Source code in spindlex/crypto/pkey.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
Attributes¶
algorithm_name property ¶
Get SSH algorithm name for this key type.
Methods:¶
__eq__(other) ¶
Compare keys for equality.
__init__(crypto_backend=None) ¶
Initialize public key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crypto_backend | Optional[CryptoBackend] | Cryptographic backend to use | None |
Source code in spindlex/crypto/pkey.py
from_private_key_file(filename, password=None) classmethod ¶
Load private key from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename | str | Path to key file | required |
password | Optional[str] | Optional password for encrypted keys | None |
Returns:
| Type | Description |
|---|---|
PKey | Loaded PKey instance |
Source code in spindlex/crypto/pkey.py
from_string(data) classmethod ¶
Create PKey instance from SSH wire format bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | bytes | Public key data in SSH wire format | required |
Returns:
| Type | Description |
|---|---|
PKey | Loaded PKey instance |
Raises:
| Type | Description |
|---|---|
CryptoException | If key loading fails |
Source code in spindlex/crypto/pkey.py
generate(key_type='ed25519', bits=2048, **kwargs) classmethod ¶
Generate a new key pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_type | str | Type of key to generate ('ed25519', 'rsa', 'ecdsa') | 'ed25519' |
bits | int | Number of bits for RSA keys (legacy, use kwargs for others) | 2048 |
**kwargs | Any | Additional arguments for specific key types | {} |
Returns:
| Type | Description |
|---|---|
PKey | New PKey instance with generated key pair |
Raises:
| Type | Description |
|---|---|
CryptoException | If generation fails or unsupported key type |
Source code in spindlex/crypto/pkey.py
get_fingerprint(hash_algorithm='sha256') ¶
Get key fingerprint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hash_algorithm | str | Hash algorithm to use (md5, sha256) | 'sha256' |
Returns:
| Type | Description |
|---|---|
str | Formatted fingerprint string |
Raises:
| Type | Description |
|---|---|
CryptoException | If fingerprint generation fails |
Source code in spindlex/crypto/pkey.py
get_name() ¶
Get the SSH algorithm name for this key.
Returns:
| Type | Description |
|---|---|
str | SSH algorithm name (e.g., 'ssh-rsa') |
get_openssh_string() ¶
Get public key in OpenSSH format.
Returns:
| Type | Description |
|---|---|
str | Public key string in OpenSSH format (e.g., "ssh-rsa AAAAB3N...") |
Source code in spindlex/crypto/pkey.py
get_public_key() ¶
Get a PKey instance containing only the public key.
Returns:
| Type | Description |
|---|---|
PKey | PKey instance with only public key loaded |
Source code in spindlex/crypto/pkey.py
get_public_key_bytes() ¶
Get public key in SSH wire format.
Returns:
| Type | Description |
|---|---|
bytes | Public key bytes in SSH wire format |
Raises:
| Type | Description |
|---|---|
CryptoException | If no key loaded |
Source code in spindlex/crypto/pkey.py
get_ssh_type() ¶
load_private_key(key_data, password=None) ¶
Load private key from bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data | bytes | Private key data (PEM or OpenSSH format) | required |
password | Optional[bytes] | Optional password for encrypted keys | None |
Raises:
| Type | Description |
|---|---|
CryptoException | If key loading fails |
Source code in spindlex/crypto/pkey.py
load_public_key(key_data) ¶
Load public key from bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data | bytes | Public key data (SSH wire format) | required |
Raises:
| Type | Description |
|---|---|
CryptoException | If key loading fails |
Source code in spindlex/crypto/pkey.py
save_to_file(filename, password=None) ¶
Save private key to file in PEM format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename | str | Path to save key file | required |
password | Optional[str] | Optional password for encryption | None |
Raises:
| Type | Description |
|---|---|
CryptoException | If saving fails |
Source code in spindlex/crypto/pkey.py
sign(data) ¶
Sign data with private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | bytes | Data to sign | required |
Returns:
| Type | Description |
|---|---|
bytes | Signature bytes in SSH format |
Raises:
| Type | Description |
|---|---|
CryptoException | If signing fails or no private key |
Source code in spindlex/crypto/pkey.py
verify(signature, data) ¶
Verify signature with public key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signature | bytes | Signature bytes in SSH format | required |
data | bytes | Original data that was signed | required |
Returns:
| Type | Description |
|---|---|
bool | True if signature is valid, False otherwise |
Source code in spindlex/crypto/pkey.py
RSAKey ¶
Bases: PKey
RSA SSH key implementation.
Implements rsa-sha2-256 key type using RSA with SHA-256.
Source code in spindlex/crypto/pkey.py
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 | |
Attributes¶
algorithm_name property ¶
Get SSH algorithm name.
Methods:¶
generate(key_type='rsa', bits=2048, *args, **kwargs) classmethod ¶
Generate a new RSA key pair.
Source code in spindlex/crypto/pkey.py
get_public_key_bytes() ¶
Get RSA public key in SSH wire format.
Returns:
| Type | Description |
|---|---|
bytes | Public key bytes in SSH wire format |
Raises:
| Type | Description |
|---|---|
CryptoException | If no key loaded |
Source code in spindlex/crypto/pkey.py
load_private_key(key_data, password=None) ¶
Load RSA private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data | bytes | Private key data (PEM format) | required |
password | Optional[bytes] | Optional password for encrypted keys | None |
Raises:
| Type | Description |
|---|---|
CryptoException | If key loading fails |
Source code in spindlex/crypto/pkey.py
load_public_key(key_data) ¶
Load RSA public key from SSH wire format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data | bytes | Public key data in SSH wire format | required |
Raises:
| Type | Description |
|---|---|
CryptoException | If key loading fails |
Source code in spindlex/crypto/pkey.py
save_to_file(filename, password=None) ¶
Save RSA private key to file.
Source code in spindlex/crypto/pkey.py
sign(data) ¶
Sign data with RSA private key using SHA-256.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | bytes | Data to sign | required |
Returns:
| Type | Description |
|---|---|
bytes | Signature bytes in SSH format |
Raises:
| Type | Description |
|---|---|
CryptoException | If signing fails or no private key |
Source code in spindlex/crypto/pkey.py
verify(signature, data) ¶
Verify RSA signature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signature | bytes | Signature bytes in SSH format | required |
data | bytes | Original data that was signed | required |
Returns:
| Type | Description |
|---|---|
bool | True if signature is valid, False otherwise |
Source code in spindlex/crypto/pkey.py
Functions:¶
get_crypto_backend() ¶
Get the default cryptographic backend.
Returns:
| Type | Description |
|---|---|
CryptoBackend | Default CryptoBackend instance |
load_key_from_file(filename, password=None) ¶
Load SSH key from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename | str | Path to key file | required |
password | Optional[str] | Optional password for encrypted keys | None |
Returns:
| Type | Description |
|---|---|
PKey | Loaded PKey instance |
Raises:
| Type | Description |
|---|---|
CryptoException | If key loading fails |
Source code in spindlex/crypto/pkey.py
load_public_key_from_string(key_string) ¶
Load SSH public key from string (OpenSSH format).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_string | str | Public key string in OpenSSH format | required |
Returns:
| Type | Description |
|---|---|
PKey | Loaded PKey instance |
Raises:
| Type | Description |
|---|---|
CryptoException | If key loading fails |