certificates:get_the_key_length_from_a_certificate
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
certificates:get_the_key_length_from_a_certificate [2016/12/06 12:05] – created peter | certificates:get_the_key_length_from_a_certificate [2019/11/26 21:49] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Certificates - Get the key length from a certificate ====== | ||
- | |||
- | ===== Using ssh-keygen ===== | ||
- | |||
- | <code bash> | ||
- | ssh-keygen -lf / | ||
- | </ | ||
- | |||
- | shows | ||
- | |||
- | < | ||
- | 2048 d1: | ||
- | </ | ||
- | |||
- | **2048** is the keylength. | ||
- | |||
- | |||
- | ===== Using openssl ===== | ||
- | |||
- | With openssl, if your private key is in file id_rsa, then: | ||
- | |||
- | <code bash> | ||
- | openssl rsa -text -noout -in id_rsa | ||
- | </ | ||
- | |||
- | will print the private key contents, and the first line of output contains the modulus size in bits. If the key is protected by a passphrase you will have to type that passphrase, of course. | ||
- | |||
- | If you only have the public key, then OpenSSL won't help directly. You can still do that with OpenSSL the following way: | ||
- | |||
- | Open the public key file with a text editor. | ||
- | |||
- | <code bash> | ||
- | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDDo2xko99piegEDgZCrobfFTvXUTFDbWT | ||
- | ch4IGk5mk0CelB5RKiCvDeK4yhDLcj8QNumaReuwNKGjAQwdENsIT1UjOdVvZOX2d41/ | ||
- | gOCD1ujjwuHWBzzQvDA5rXdQgsdsrJIfNuYr/ | ||
- | JXTVQ5Whc0mGBU/ | ||
- | 5tCWIptu8u8ydIxz9q5zHxxKS+c7q4nkl9V/ | ||
- | OEoiL1YH1SE1U93bUcOWvpAQ5 server1@sharewiz.com | ||
- | </ | ||
- | |||
- | With your mouse, select the first characters of the middle blob (after the ssh-rsa); this is Base64 and OpenSSL can decode that: | ||
- | |||
- | <code bash> | ||
- | echo " | ||
- | </ | ||
- | |||
- | OpenSSL is picky, he will require that you input no more than 76 characters as one line, and the number of characters must be a multiple of 4. The line above will print out this: | ||
- | |||
- | < | ||
- | 00000000 | ||
- | 00000010 | ||
- | 00000020 | ||
- | </ | ||
- | |||
- | This reads as such: | ||
- | |||
- | < | ||
- | 00 00 00 07 The length in bytes of the next field | ||
- | 73 73 68 2d 72 73 61 The key type (ASCII encoding of " | ||
- | 00 00 00 03 The length in bytes of the public exponent | ||
- | 01 00 01 The public exponent (usually 65537, as here) | ||
- | 00 00 01 01 The length in bytes of the modulus (here, 257) | ||
- | 00 c3 a3... The modulus | ||
- | </ | ||
- | |||
- | So the key has type RSA, and its modulus has length 257 bytes, except that the first byte has value " | ||
certificates/get_the_key_length_from_a_certificate.1481025934.txt.gz · Last modified: 2020/07/15 09:30 (external edit)