### Question:
KeypairService { public String getPublicKeyString(PublicKey pubKey) { ByteArrayOutputStream out = new ByteArrayOutputStream(); RSAPublicKey publicKey = (RSAPublicKey) pubKey; byte[] sshrsa = new byte[] {0,0,0,7,'s','s','h','-','r','s','a'}; try { out.write(sshrsa); BigInteger e = publicKey.getPublicExponent(); byte[] data = e.toByteArray(); encodeUInt32(data.length, out); out.write(data); BigInteger m = publicKey.getModulus(); data = m.toByteArray(); encodeUInt32(data.length, out); out.write(data); byte[] outArr = out.toByteArray(); String outString = Base64.encodeBase64String(outArr); outString = "ssh-rsa " + outString; return outString; } catch (IOException e) { e.printStackTrace(); } return null; }  KeyPair createKeypair(); String getPEM(PrivateKey privKey); String getPublicKeyString(PublicKey pubKey);  }### Answer:
@Test public void testGetPublicKeyString() { KeyPair kp = keypairService.createKeypair(); PublicKey publicKey = kp.getPublic(); String publicKeyString = keypairService.getPublicKeyString(publicKey); assertNotNull(publicKeyString); assert(publicKeyString.startsWith("ssh-rsa")); }