Github Generate Ssh Public Key

Posted : admin On 15.12.2020

SSH keys come in pairs, a public key that gets shared with services like GitHub, and a private key that is stored only on your computer. If the keys match, you're granted access. The cryptography behind SSH keys ensures that no one can reverse engineer your private key from the public one. Generating an SSH key. /camtasia-studio-9-key-generator.html. How to Generate SSH key for Git. SSH keys are an access credential used in SSH protocol (Secure Shell) which is a network protocol that helps to login from one computer to another securely, as well as to manage networks, operating systems, and configurations. Download firefox 54 for mac.

Ssh public key windows
Generate SSH public keypair from SSH RSA/DSA/EC private key in Scala
Github

Github Create Public Ssh Key

genssh.scala

Ssh Key Github

importjava.io.{DataOutputStream, ByteArrayOutputStream, StringReader}
importjava.security.interfaces.{ECPublicKey, DSAParams, DSAPublicKey, RSAPublicKey}
importjava.security._
importjava.security.spec.X509EncodedKeySpec
importorg.apache.commons.codec.binary.Base64
importorg.bouncycastle.openssl.{PEMKeyPair, PEMParser}
objectgenPubSSHKey {
/**
* Generates a public key from a SSH private key.
* @paramprivateKey A RSA/DSA/EC private key
* @return SSH encoded public key
*/
defgetPublicKey(privateKey: String):String= {
valkp:PEMKeyPair=newPEMParser(newStringReader(privateKey)).readObject().asInstanceOf[PEMKeyPair]
valx509=newX509EncodedKeySpec(kp.getPublicKeyInfo.getEncoded)
valkeyFactory=if (privateKey.startsWith('-----BEGIN RSA PRIVATE KEY-----')) {
KeyFactory.getInstance('RSA')
} elseif (privateKey.startsWith('-----BEGIN DSA PRIVATE KEY-----')) {
KeyFactory.getInstance('DSA')
} elseif (privateKey.startsWith('-----BEGIN EC PRIVATE KEY-----')) {
KeyFactory.getInstance('EC')
} else {
thrownewException('Incompatible SSH key algorithm')
}
encodePublicKey(keyFactory.generatePublic(x509),'ozone')
}
privatedefencodePublicKey(publicKey: PublicKey, user: String):String= {
varpublicKeyEncoded:String=null
if (publicKey.getAlgorithm 'RSA') {
valrsaPublicKey:RSAPublicKey= publicKey.asInstanceOf[RSAPublicKey]
valbyteOs:ByteArrayOutputStream=newByteArrayOutputStream
valdos:DataOutputStream=newDataOutputStream(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)
publicKeyEncoded =newString(Base64.encodeBase64(byteOs.toByteArray))
s'ssh-rsa $publicKeyEncoded user'
}
elseif (publicKey.getAlgorithm 'DSA') {
valdsaPublicKey:DSAPublicKey= publicKey.asInstanceOf[DSAPublicKey]
valdsaParams:DSAParams= dsaPublicKey.getParams
valbyteOs:ByteArrayOutputStream=newByteArrayOutputStream
valdos:DataOutputStream=newDataOutputStream(byteOs)
dos.writeInt('ssh-dss'.getBytes.length)
dos.write('ssh-dss'.getBytes)
dos.writeInt(dsaParams.getP.toByteArray.length)
dos.write(dsaParams.getP.toByteArray)
dos.writeInt(dsaParams.getQ.toByteArray.length)
dos.write(dsaParams.getQ.toByteArray)
dos.writeInt(dsaParams.getG.toByteArray.length)
dos.write(dsaParams.getG.toByteArray)
dos.writeInt(dsaPublicKey.getY.toByteArray.length)
dos.write(dsaPublicKey.getY.toByteArray)
publicKeyEncoded =newString(Base64.encodeBase64(byteOs.toByteArray))
s'ssh-dss $publicKeyEncoded $user'
} elseif (publicKey.getAlgorithm 'EC') {
valecPublicKey:ECPublicKey= publicKey.asInstanceOf[ECPublicKey]
valbyteOs:ByteArrayOutputStream=newByteArrayOutputStream
valdos:DataOutputStream=newDataOutputStream(byteOs)
valcurveName= ecPublicKey.getParams.getCurve.getField.getFieldSize match {
case256=>'nistp256'
case384=>'nistp384'
case521=>'nistp521'
case _ =>thrownewException('Unknown curvesize')
}
valfullName=s'ecdsa-sha2-$curveName'
dos.writeInt(fullName.getBytes.length)
dos.write(fullName.getBytes)
dos.writeInt(curveName.getBytes.length)
dos.write(curveName.getBytes)
valgroup= ecPublicKey.getW
valelementSize:Int= (ecPublicKey.getParams.getCurve.getField.getFieldSize +7) /8
valM:Array[Byte] =newArray[Byte](2* elementSize +1)
M(0) =0x04.toByte
valaffineX:Array[Byte] = group.getAffineX.toByteArray.dropWhile(_ 0x00)
Array.copy(affineX, 0, M, 1+ elementSize - affineX.length, affineX.length)
valaffineY:Array[Byte] = group.getAffineY.toByteArray.dropWhile(_ 0x00)
Array.copy(affineY, 0, M, 1+ elementSize + elementSize - affineY.length, affineY.length)
dos.writeInt(M.length)
dos.write(M)
publicKeyEncoded =newString(Base64.encodeBase64(byteOs.toByteArray))
s'$fullName $publicKeyEncoded $user'
}
else {
thrownewIllegalArgumentException('Unknown public key encoding: '+ publicKey.getAlgorithm)
}
}
}

Github Generate Ssh Public Key Format

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment