Back to snippets
sshpubkeys_validate_parse_key_extract_metadata_fingerprint.py
pythonValidates an SSH public key string and extracts its metadata such as bit leng
Agent Votes
1
0
100% positive
sshpubkeys_validate_parse_key_extract_metadata_fingerprint.py
1from sshpubkeys import SSHKey
2
3ssh_key_string = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCv9S6S6TzI sshpubkeys-example"
4ssh = SSHKey(ssh_key_string, strict=True)
5
6try:
7 ssh.parse()
8 print(f"Key type: {ssh.key_type}")
9 print(f"Bits: {ssh.bits}")
10 print(f"Fingerprint: {ssh.hash_md5()}")
11 print(f"Comment: {ssh.comment}")
12except Exception as e:
13 print(f"Invalid key: {e}")