ssh - How to get modulus and pubExp in java? -
is possible retrieve modulus , pubexp ssh public key such 1 below:
ssh-rsa aaaab3nzac1yc2eaaaadaqabaaabaqc9t1iuplxcsaame3qpxib4g1btzhh4ok4ti2phgfoedlsvwrhycx+f8gbnnratonkgjodh9wwku1eibbd2qpsfrryowvme85teqxrt1mjpmsxrdkrla4a9nlghtarozpntxkubhjdqkfgmnid/ryuw3maj+khw1luex+wpalylntnjp0rfgo72x47wnelvolczttastqrnch1clcy2wq4kmfovzago1srtrolc/6k17oeo7eqrwgt4iwjls9hynxniccn5hg313iryjj6zq/er/ormm7t8lmh8479qzdxinsk3gnccw3xrdzyd/zclsagkwuna+0g0judxezqpgmhr user@mc-s08347cdc1.local
i need these parameters somehow key above can execute code below generate , public key in java
rsapublickeyspec ks = new rsapublickeyspec(modulus, pubexp); rsapublickey pubkey = (rsapublickey)keyfactory.generatepublic(keyspec);
apparently ssh keys use format defined in rfc 4253. can base64 decode data (e.g. using apache commons codec library) , parse binary result yourself.
this output of base64 decoded string (you may need postfix 2, 3 or 4 '=' characters decoder work, need multiple of 4 base64 encoded characters):
000000077373682d727361000000030100010000010100bdb75894a655c2b1a6a613740fc620781b50536471f8a0ae138b6a4781f3840cbb155ab87271
now lets dissect (first part 4 bytes length in big endian format):
00000007 7373682d727361 // "ssh-rsa" string in ascii 00000003 010001 // public exponent, fourth number of fermat or 65537 in decimals 00000101 00bdb75894a655c2b1a6a613740fc620781b50536471f8a0ae138b6a4781f3840cbb155ab87271
well last part modulus. 129 bytes instead of 128 because library seems use signed integers. 1024 bit modulus starts first bit set one, can sure there 00
valued padding byte left of unsigned representation.
happy coding, info taken here.
Comments
Post a Comment