private def toAuthorizedKey()

in src/main/scala/com/gu/ssm/utils/KeyMaker.scala [32:44]


  private def toAuthorizedKey(key: Key, description: String) = {
    val rsaPublicKey = key.asInstanceOf[BCRSAPublicKey]
    val byteOs: ByteArrayOutputStream = new ByteArrayOutputStream
    val dos = new DataOutputStream(byteOs)
    dos.writeInt ("ssh-rsa".getBytes.length)
    dos.write ("ssh-rsa".getBytes)
    dos.writeInt (rsaPublicKey.getPublicExponent.toByteArray.length)
    dos.write (rsaPublicKey.getPublicExponent.toByteArray)
    dos.writeInt (rsaPublicKey.getModulus.toByteArray.length)
    dos.write (rsaPublicKey.getModulus.toByteArray)
    val publicKeyEncoded = new String (Base64.encodeBase64 (byteOs.toByteArray) )
    "ssh-rsa " + publicKeyEncoded + " " + description
  }